What I’m trying to do is make a user able to enter multiple options from a prompt, and I can’t make it so that it doesn’t matter if “rcz” is entered with or without capital letters, I always get the same error.
I need my counter to appear in the console, but instead I got this:
Uncaught TypeError: Cannot read properties of null (reading ‘toLowerCase’)
at anonymous :31:42
Code I’m using:
alert(`Choose one or more cars. If you want to stop press ESC`);
let userPrompt = prompt(`Available cars: 208, 308, RCZ`);
let promptToLC = userPrompt.toLowerCase();
let counter = 0;
while(userPrompt != null) {
switch(promptToLC) {
default:
alert(`We don't have that car. Try again.`);
break;
case "208":
counter = counter + 1;
break;
case "308":
counter = counter + 1;
break;
case "rcz":
counter = counter + 1;
break;
}
userPrompt = prompt(`Available cars: 208, 308, RCZ`);
promptToLC = userPrompt.toLowerCase();
}
console.log(counter);