.toUpperCase bugs my code (SOLVED)


#1

I finished all sections for the code your own adventure 2. However, I noticed that when my prompt has .toUpperCase in the end, it makes the code go straight to the default, even when I properly type in the cases in my switch code. Here is the var and switch:

var user = prompt("Will you listen?").toUpperCase();

switch(user) {
case 'Blog': if (user && user) {
}
else
{ }
console.log("I prefer the blog");
break;
case 'Video':if (user || user) {
}
else { }
console.log("I prefer the videos");
break;
case 'In person': if (user || user) {
}
else { }

console.log("I prefer to meet in person");
break;
default: console.log("this is the default");

}

When I remove the touppercase, I get all parts of the switch working right. Why does it do that?


#2

It doesn't work because you changed the prompt's answer into UPPERCASE and then base all of your cases on non UPPERCASE things. All of your cases need to be uppercase:

Should be

case 'BLOG': 
 if (user && user) {

etc.


#3

Got it, tested it, changed it, it works now.

I must have read the explanation wrong then. I thought it only referred to the user input when answering a prompt. I didn't expect it to also affect how I write the cases. Thank you.

Noted.


#4

Your welcome. Now could you please mark this topic as solved so no one else responds? Thanks.


#5

Thank you! Your answer here helped me, too. 😊