1. Store the choices
An array is a list. Each member is an object with two properties: name for the standard name and aliases for accepted spellings.
{ name: "Nova", aliases: ["nova", "novah"] }Code Zone Bug Lab / Episode 18
Learn how arrays, objects, and a loop turn messy names into a roster match. Predict ten results, investigate a punctuation bug, then transfer the skill to a new problem.

Learn it → trace it → try it
Imagine a space club that receives a name already extracted from a badge. A nickname, uppercase letters, or extra spaces should still lead to the right member. An unknown name should stay unknown.
Start here · What you will change
The starter already handles uppercase letters, surrounding spaces, and approved nicknames. You have two additions to make in the JS tab:
.), commas (,), exclamation marks (!), and question marks (?) at the end of the first word, before looking for that word in the aliases array.rob, robert, bobby, and robbie. Keep the existing members and the reusable loop.For example, "Milo." and "Milo?!" should match Milo. "Nova!" should match Nova, and "Pip?" should match Pip. A name outside the roster, such as "Samantha", must still return "" (no match).
Work on punctuation first, then add Rob. You are changing the cleanup and the roster data, not writing a separate condition for every input.
An array is a list. Each member is an object with two properties: name for the standard name and aliases for accepted spellings.
{ name: "Nova", aliases: ["nova", "novah"] }trim() removes spaces at the ends. toLowerCase() makes letter case consistent. split(/\s+/)[0] takes the first word, even with repeated spaces.
" NOVAH Reed " becomes "novah". These three operations do not remove punctuation: "Milo." still becomes "milo.", which is different from the alias "milo".
for...of visits each member. includes(first) asks whether that member’s alias list contains the whole first word. It does not guess similar names.
for (const member of MEMBERS) {
// Check this member's aliases.
}return member.name sends the match back and ends the function. A final return "" means no match after checking everyone.
The type check stops missing or non-text input before string methods run.
Read the cleaning lines in order. Each step prepares the value for the next one:
trim() removes spaces at the beginning and end: " Milo! Reed " becomes "Milo! Reed".toLowerCase() makes the letters lowercase: "milo! reed".split(/\s+/)[0] separates words at whitespace and keeps the first one: "milo!". The ! is still attached because it is not a space."milo", then compare that value with each member’s aliases.Find const cleaned and const first inside toMember. Put the punctuation cleanup before the loop’s includes(first) comparison.
const cleaned = spoken.trim().toLowerCase();
const first = cleaned
.split(/\s+/)[0]
.replace(/[.,!?]+$/, "");replace() returns text with a matching part replaced. Here, the matching part is punctuation at the end of the first word, and "" replaces it with nothing.
[.,!?] matches any one of the four listed punctuation marks.+ allows one or more marks, so "Milo?!" also works.$ limits removal to the end of this first word.The split and replace operations are chained: the first supplies the word, and the next cleans it. The final result is stored in first, so the existing includes(first) line can stay as it is.
This ticket only removes these four trailing marks. It does not remove letters, alter punctuation inside a name, or guess who an unknown person might be.
" NOVAH Reed "."novah reed". First word: "novah"."Nova".Now explain what happens when no member matches. Why must the empty return come after the loop?
Known problems · Your ticket queue
Report: “MILO works, but Milo. comes back as unknown.” Reproduce both inputs. In toMember, update the first-word cleaning before the loop so it removes trailing periods (.), commas (,), exclamation marks (!), and question marks (?). Test a repeated ending such as Milo?! too.
Done when: Known names match with or without these trailing marks, and unknown names still return no match. Other special characters are outside this ticket.
Report: “Our fictional club hired Rob. He also goes by Robert, Bobby, or Robbie. None of those names are recognized yet.”
Your task: Add one member object with the standard name "Rob" and four lowercase aliases. Keep the lookup function reusable rather than adding a separate if statement for Rob.
Retest: "Rob", "ROBERT", " bobby ", "Robbie.", and "Robert from Star Club" should return "Rob". "Robin" and "Roberta" should stay unmatched. Milo, Nova, and Pip must still work.
The array is the roster. Each object describes one employee; the aliases array lists approved names for that employee. The loop already checks every object, so adding one object lets it find a new person without rewriting the search.
// Example shape only — fill in your own values.
{ name: "Standard name", aliases: ["alias one", "alias two"] },Keep commas between the objects. Store aliases in lowercase because the function lowercases the input before comparing it.
Need a starting point? Choose Load beginner TODOs above the editor. You can cancel without losing work. Its comments show where to investigate, not the completed answer. Choose Load explainer comments for a line-by-line explanation of the array, objects, string methods, conditions, loop, and return statements.
Allow 30 minutes. Use this page as your sandbox. Close AI assistants for this attempt; documentation is fine. Write predictions for the current starter, then run each case. Repair the punctuation case first, then complete the new employee add-on and retest. Check my fix covers both tickets; Rob-related checks stay red until you add his object. Your notes save in this browser and sync to your account when signed in. Run current code fills the preview input and logs its result without changing your code or writing your observations for you.
| Input | Your prediction | Observed result | Try it |
|---|---|---|---|
"Milo." | |||
"MILO" | |||
"Miles from Star Club" | |||
"Mylo" | |||
" nova " | |||
"Samantha" | |||
"" | |||
"Pippin Reed" | |||
" " | |||
null |
Choose a row to try it using your current editor code. Read the Console and record what you observed.
The null row’s Run current code button passes a real non-text value to the function. You can also try console.log(toMember(null)); in the JS tab. Add two tests of your own and explain your fix without reading the code aloud word for word.
Documentation: String.replace (new tab) ↗ · for...of (new tab) ↗
Your sprint ticket · In progress · DEV-161
Customer report: Milo is on our pretend Star Club roster, but a badge entered as Milo. returns no match.
The input is an already extracted name, not a whole conversation. Only approved aliases count. Do not add fuzzy matching or accept everyone.
Fictional learning demo. Use invented inputs only. No client systems or credentials are connected.
Reproduce → inspect → hypothesize → verify
Start with the two tasks and the cleaning walkthrough above. In the JS tab, update the first-word cleaning in toMember to remove trailing . , ! and ? before matching. Then add Rob and his four aliases to MEMBERS. The HTML and CSS are provided. Use Check challenge after you have recorded predictions and investigated. Checks include null and non-text inputs that cannot be entered directly in the text field.
Choose TODO guidance for where to investigate, or explainer comments for what each line does. Both leave the fixes for you. Loading a starter replaces edits only after you confirm. Reset keeps your selected mode.
Checking account and saved lab work…
Sign in to sync across devicesChoose the copy to continue with. Keeping the device copy replaces the account copy only after a revision check.
Loading the JavaScript and HTML editor…
Pass the checks or make three attempts to unlock an explained example.
Ready to test? Choose “Check challenge” after investigating.
Code and prediction notes recover in this browser and sync when signed in. Instructor examples stay separate. Reset replaces code, not prediction notes.
Replace your edits with the original broken example?
Try first. Reveal one clue at a time.
For Milo., what are cleaned and first? Compare that first word with the aliases in the array.
A period is a punctuation character. Remove trailing punctuation from the first word before checking aliases instead of adding every punctuation variant to the list.
String.replace can remove matching characters. For this ticket, remove one or more trailing periods, commas, exclamation marks, or question marks. Keep the string check and the no-match return.
Your lab report
“I expected… I observed… The console showed… My hypothesis was… I changed… I verified…”
Use Check challenge for automated behavior checks. Passing checks are useful evidence, not a complete code review.
Give others room to investigate: label solutions as spoilers.
Share your lab report on SKOOL (new tab) ↗Exercise B · 20 minutes
Build a lookup for fictional observatory accounts. The data changes; the four steps stay useful.
Start the account exercise →Finish with a five-minute explanation: What does the function receive? What does it return? What happens when nothing matches?