4. Switch... doesnt work


#1

//my code doesnt work
// it says "unexpected token"
var user = prompt("Do you like apples?").toUpperCase();
switch(user) {
case 'yes':
console.log("nice");
break;
case 'no';
console.log("okay, bye");
break;
}
//whats wrong


#2

case 'no';

it's not expecting a ;.

However there's another problem..

You're checking for cases that are lowercase, however when getting input you are setting the input to uppercase. The switch will never work in that way...


#3

Hi webblaster

var user = prompt("Do you like apples?").toUpperCase();
switch(user) {
case 'yes':
console.log("nice");
break;
 
case 'no';
// minor error ... need to use a colon (:)
// change this over to case 'NO':
console.log("okay, bye");
break;
}
//whats wrong

// also as jacob has indicated...
in your prompt you have added .toUpperCase();
so effectively you are changing your response characters from lowerCase to upperCase so 'yes' becomes 'YES'
so remember the case would also need to be written to account for the .toUpperCase(); modification

case 'yes': //  modify this to case 'YES':
console.log("nice");

// the task asks you to also add at least three so remember to add another one after case 'NO':
Create as many as you like! (Do at least three.)
// lastly have a look at the Hint as it also shows you one final part of creating the switch that you need to add after the three case(s) you create

  default:
        console.log("I don't know you!");

I am doing the same task too at the moment
hope that makes sense and helps


#4

thanks man, youve been a big help


#5

glad it made some sort of sense ....I have been making so so so so....so many mistakes haha Gud job we all have access to this forum to help each other out when we get stuck on a task. I feel like I ought to pitch up a tent on this forum lately..


#6

Also you might need to put a default at the end.