Code Your Own Adventure 2: 4. Switch

Hi there, my code passed though why am I only receiving my default answer?

https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/4?curriculum_id=506324b3a7dffd00020bf661#

var user = prompt (“Do you want to run for city council?”).toUpperCase();

switch(user) {
case ‘Yes’:
console.log(“Awesome, let’s get started!”);
break;
case ‘No’:
console.log(“Why not, we need you!”);
break;
case ‘Maybe’:
console.log(“Ok, how can we help you?”);
break;
default:
console.log(“OK, maybe next year!”);
}

Since you are using .toUpperCase(), switch is passing in things like YES, NO. In this case the switch case statement only does a direct matching meaning that you will always get the default answer. YES != Yes . I would either uppercase all of your cases or lower case them and make the user = lower case prompt as well.

Have a good day :slight_smile: .

1 Like

Hmm, still not following. I changed the code to and entered YES and yes, and still got my default answer.

var user = prompt (“Do you want to run for city council?”).toLowerCase();

switch(user) {
case ‘Yes’:
console.log(“Awesome, let’s get started!”);
break;
case ‘No’:
console.log(“Why not, we need you!”);
break;
case ‘Maybe’:
console.log(“Ok, how can we help you?”);
break;
default:
console.log(“OK, maybe next year!”);
}

If you use .toLowerCase() then all of your case’s need to be completely in lower case.
Like so: case 'yes':

Oh wait, I get it now. Thank you!

^^ No problem, glad I could help.

1 Like