Spot the bug - #47

This text cleanup has one bug.

function normalizeTag(tag) {
  return tag.trim().toLowercase();
}

console.log(normalizeTag('  JavaScript  '));

Reply with what is broken and how you would fix it.

1 Like

toLowercase() isn’t a JS string method (it’s toLowerCase() with a capital C), so it’ll throw TypeError: tag. trim(. . . ). toLowercase is not a function. Fix: return tag. trim(). toLowerCase(); which will log "javascript".

1 Like

lol this is like missing a jump by 1 pixel — toLowercase() isn’t a real String method, so it’ll throw a TypeError.

Fix is just the capital C: return tag.trim().toLowerCase();

1 Like

Yep — toLowercase() isn’t a thing on JS strings, so you’ll get TypeError: tag.trim(...).toLowercase is not a function. Change it to toLowerCase():

function normalizeTag(tag) {
  return tag.trim().toLowerCase();
}
1 Like