Can anyone tell me what wrong?


#1

this code passes,but every time it posts the default answer


#2

Your question is a little vague... what is your code?


#3

It does same thing for me! Any switch case, the answer I get is default. It works if I take the .toUpperCase () away :confused:

Part of my code (took out the remaining switches):

var user = prompt("What meal would you like for dinner?").toUpperCase();

switch(user) {
case 'Indian':
var t = prompt("Do you have turmeric?").toUpperCase();
var g = prompt("Do you have ginger?").toUpperCase();
if ( t === 'yes' || g === 'yes') {
console.log("OK, not great but you can still cook with one spice!");
}
else if ( t === 'yes' && g === 'yes') {
console.log("Great, both spices will make it perfect!");
}
else {
console.log("Sorry that won't make an Indian meal!");
}
break;

case 'Chinese':
..etc....
case 'Thai':
...etc...

default:
console.log("e");
}


#4

You have one little problem there. In your code, where there's

t === 'yes' || g === 'yes'

and

t === 'yes' && g === 'yes'

you put the "yes" into lower case. The reason that it does not work is that the code takes the answer to upper case, which can not work with the codes because you made it lower case. You can correct this by either changing all the

to.UpperCase();

to

to.LowerCase();

this will most likely get your problem solved. You can also change all the "yes"'s to upper case, but it takes longer than just changing the to.UpperCase(); to to.LowerCase();.

Hope it helped!:smiley:


#5

Awww you're a genius! Yes it indeed works now. :smiley: Thanks!