Code your own adventure 2, && doesnt run properly


everything runs smootly except for the if && part line 8 which logs as else.When I input "chocolate" and "yes" it logs "very tasty" instead of "a classic". What is wrong with it?Thanks in advance

var user=prompt("what is your favorite candy?").toLowerCase();

    switch(user) {
        case "cake":
         var kind =prompt("chocolate? , vanilla? strawberry?").toLowerCase();
         var top=prompt("mousse yes or no?").toLowerCase();
                if(kind==="chocolate" && top==="yes"){
            console.log("a classic!");
            else {
                console.log("very tasty");
            case "muffin":
         var type=prompt("blueberry? chocolate chip? caramel?").toLowerCase();
              if (type=== "blueberry" ||type==="caramel"){
                console.log("yes a good one");
              else {
                  console.log("I like chocolate chip too");
                case"mr. sark":
                case "ice cream":
                    var taste= prompt("soft? sandwich? gelato?").toLowerCase();
                    if(taste==="gelato" ||taste==="soft") {
                    console.log("of course");
                    else {
                    console.log("except that");


top seems to be a reserved word in js. you can see this when you insert an alert:

var top=prompt("mousse yes or no?").toLowerCase();

the solution is simple, use topping as your variable name


Yes! Thank you! Works fine now,I am relieved it was something irrelevant with my logic..
Thank you!


your logic was fine, you just stumbled on a reserved keyword, you can find all keywords here

might be useful, just in case


This has happened before with "this" if I remember correctly and I figured it out by accident.Thank you for the list definetely useful. I copy pasted your code at the end and run it so what does it do exactly? does it prompt after all other prompts?like universaly if that makes sense?


what? alert?

alert() is just like prompt() except it just display information to the user (without the user having to enter something)


ok, thank you for your help and prompt responses.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.