#4 Switch - My code looks right but only default works


#1

Can someone take a look for me please? My code looks right but only the default outcome works. I am passing the lesson but want to ensure that the rest of the exercise will work if my switch statement is not truly working properly.

Thank you!

var user = prompt("What's your name?").toUpperCase();

switch(user) {
case 'Dany':
console.log("Pretty name!");
break;
case 'Ming':
console.log("Is that your dog's name?");
break;
case 'Ian':
console.log("My fave!");
break;
default:
console.log("How do you spell it?");
}


#2

I tried to switch it to make for a better "Code your adventure" in the next part of the exercise and now only the first option works? I did setup the first case and then copy and past the next two and the default. Could that have any effect on it?

var user = prompt("Where do you want to go? Jamaica, France or China?").toUpperCase();

switch(user) {
case 'Jamaica':
console.log("Sunshine, here I come!");
break;
case 'France':
console.log("Welcome to France!");
break;
case 'China':
console.log("Don't forget to buy souvenirs");
break;
default:
console.log("Where do you want to go?");
}


#3

You are converting whatever the user types in to uppercase. eg

#I type in              :=> jamaica
#what is stored in user :=> JAMAICA

You need to be checking the uppercase forms of all the cases you want to check


#4

To be clear:

I should have typed JAMAICA, FRANCE or CHINA in the prompt to tell the program what to convert uppercase?


#5

No, I think what rydan meant was: You should check for JAMAICA, FRANCE and CHINA in your switch code,
e.g. case 'JAMAICA': etc.
This is because the input to the prompt is converted to uppercase letters before the code continues to the switch part.

Hope this helps?


#6

It does
thank you!
I went back and played with it.