8. All on your own "Switch"


#1

Need a bit help her, looking at the code I just can'T see where I'm going wrong.
after "Save & Submit Code" error returns: Oops, try again. Make sure you have a break statement for each case.

var answer = prompt("Question", "Text");

switch(answer) {
    case 'case1':
        console.log("Console reply for case 1.");
        break;
    case 'case2':
        console.log("Console reply for case 2.");
        break;
    case 'case3':
        console.log("Console reply for case 3.");
        break;
    default:
        console.log("Console reply for default.");
        break;
}

#2

@001aa100,
It seems you have caused a disturbance
in the code-checker by using the 'case1','case2' and 'case3'

It checks for the amount of occurences of the word 'case'
and then compares that to amount of appearances of the 'break'....

It expects a break for every occurence of 'case'
but in your code you have 6 case words.....!!!!!!


#3

Thank you, changed the "case's" with the word "example" and it worked... so I just confused the poor computer, my bad :slight_smile:


#4

My code is // Write your code below!
var snack = prompt"What's your favorite snack? Choices: granola bar, fruit, cookie.";
switch(snack) {
case 'granola bar':
console.log("Yuck.");
break;
case 'fruit':
console.log("I wonder what fruit?");
break;
case 'cookie':
console.log("Yummy! Do you have one? Can I have it? Nom nom nom. BURP!")
break;
default:
console.log("Do you like potatoes?");
break;
}
and it says
Oops, try again.
There was a problem with your syntax.


#5

Hi you should put yout string inside the () like that

prompt("What's your favorite snack? Choices: granola bar, fruit, cookie.");