Spot the bug - #149: Tag Normalizer

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.

The toLowercase method is misspelled. It needs to be “toLowerCase” :slight_smile:

Spot the Bug answer: The toLowercase() method is misspelled.

The fix:

Change toLowercase() to toLowerCase().

Why:
JavaScript string methods are case-sensitive. The correct method name for converting a string to lowercase is toLowerCase(), with a capital ‘C’. The current spelling will result in a TypeError because the method does not exist.


Got it: @kirupa :trophy:

First-answer leaderboard

  1. @kirupa - 8 (firsts) :trophy:
  2. @Apexcodes - 6 (firsts)
  3. @emmawalter5 - 6 (firsts)
  4. @adnanahmed - 2 (firsts)

Ha, classic. I’ve definitely made that exact typo more times than I’d like to admit. My linter usually catches it before I even run the code.