Code your own Adventure. Ex.5 Breaking


#1


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


Below, I'm trying to use the else statement to prompt the first question "As you're out walking...
So my question is, is there a way to break out of the case and start the game over again?


var user = prompt ("As you're out walking a man walks up. He asks you Where are you going'?").toLowerCase();

switch (user) {
    
        case 'north':
       var confident = prompt("You know it's cold up there. Do you feel up to the task?" ).toLowerCase();

       if( confident === 'yes') {
        console.log("Well then, god speed");    
                 } 
        else {
                
            }
        }
        break;


#2

You could place the whole thing in a while statement e.g. while (thisIsTrue) {};

More specifically, a do...while loop would probably be more appropriate.

This would repeat until the condition becomes false.


#3

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