# Spot the bug - #118: Name Badge Generator

**URL:** <https://forum.kirupa.com/t/spot-the-bug-118-name-badge-generator/683068>\
**Category:** web dev\
**Created:** [August 16, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-118-name-badge-generator/683068 "2026-08-16T07:00:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [August 16, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-118-name-badge-generator/683068/1 "2026-08-16T07:00:08Z")

</div>

My cute wizard title formatter keeps printing undefined words.

```js
function formatWizardGreeting(rawName, rank) {
  const cleanName = rawName.trim();
  const safeRank = rank.toLowerCase();

  let prefix = '';
  if (safeRank === 'archmage') {
    prefix = 'The Grand';
  } else if (safeRank === 'apprentice') {
    prefix = 'Novice';
  } else {
    prefix = 'Traveler';
  }

  // Capitalize first letter of wizard name
  const firstChar = cleanName.charAt(0).toUpperCase();
  const restOfName = cleanName.subString(1).toLowerCase();
  const styledName = firstChar + restOfName;

  const magicBanner = `*~ ${prefix} ${styledName} ~*`;
  return magicBanner.repeat(1);
}

const greeting = formatWizardGreeting(' gANDALF ', 'archmage');
console.log(greeting);

```

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

---

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [August 17, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-118-name-badge-generator/683068/2 "2026-08-17T07:00:17Z")

</div>

The `subString` method is misspelled. It should be `substring` with a lowercase ‘s’. JavaScript string methods are case-sensitive, so `subString` isn’t found, leading to `undefined` in the output.

```auto
const restOfName = cleanName.substring(1).toLowerCase();

```

---

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [August 17, 2026, 8:00am UTC](https://forum.kirupa.com/t/spot-the-bug-118-name-badge-generator/683068/3 "2026-08-17T08:00:12Z")

</div>

**Spot the Bug answer:** The String.prototype.subString method is misspelled as subString instead of substring.

**The fix:**

```js
Change cleanName.subString(1) to cleanName.substring(1).

```

**Why:**  
JavaScript string methods are case-sensitive. The correct method name for extracting a part of a string is ‘substring’ (all lowercase). Using ‘subString’ results in a TypeError because the method does not exist on the String prototype, causing the restOfName variable to be undefined and leading to ‘undefined’ in the output.

**First-answer leaderboard**

1. @kirupa - 4 (firsts) 🏆
2. @adnanahmed - 2 (firsts)
3. @emmawalter5 - 1 (first)
