0

Forgive the newbie question as I am just starting a course on HTML, CSS, and Javascript but I wanted to ask a question to see how others would tackle the issue.

For instance, you have this script:

var guestList = ["Kevin", "Angela", "Mike"];

var guestName = prompt("What is your name? ");

if (guestList.includes(guestName)) {
    console.log("Welcome " + guestName);
} else {
    console.log("Not on list. " + guestName);
}

When I run it and input a name with the exact letters there are no issues. However, if I forget to capitalize the first letter then it acts as if the guest isn't on the list. My thought was to either capitalize or lowercase all letters so the computer can compare the exact strings and get a proper match. However, this doesn't feel like the right answer. I think there would be a more elegant way to code this.

So how would you prepare the data to get around this issue?

  • 2
    Your intuition is the commonly used way to do what you want. In most languages theres a canonical way to compare strings ignoring case – Jamiec Jan 06 '22 at 15:52

0 Answers0