5. Code your own adventure 2


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I’m not sure if my case play dead is correct. It only returns statement after else not if. What should I correct?



Replace this line with your code. 
var user = prompt("You're walking trought the jungle and suddenly polar bear appears. What do you do? FIGHT/RUN/PLAY DEAD").toUpperCase();
switch(user) {
    case 'FIGHT':
            var weaponType = prompt("What wepon do you have? MACHETE/GUN/NONE").toUpperCase();
            switch(weaponType){
                case 'MACHETE':
                    var slice = prompt("Are you a gladiator? Y/N").toUpperCase();
                    var wield = prompt("Can you at least wield swords? Y/N"); 
                    if (slice || wield === 'Y'){
                        console.log("You swiftly dash to the side while the bear tries to head-butt you and slice his throat. You have saved yourself and defeated the mighty BEAR!");
                    }
                    else {
                        console.log("R.I.P");
                    } 
                break;    
                case 'GUN':    
                    var bang = prompt("Are you accurate? Y/N").toUpperCase();
                    var shot = Math.random();
                    if (bang === 'Y' && shot > 0.3){
                        ("Headshot! You have saved yourself and defeated the mighty BEAR!");
                        }
                    else {
                        console.log("You missed your only bullet. At least the bear isn't hungry anymore.");
                    }    
                break;
                case 'NONE':
                console.log("R.I.P");
                break;
                }
        break;
    case 'RUN':
        var runForest = prompt("Do you see any place to hide? Y/N").toUpperCase();
        if (runForest === 'Y'){
            console.log("Bears are really fast, but you could escape just to slide into the hide. Bear got bored and left you alone. You saved yoursef from the mighty BEAR!");
            }
        else {
            console.log("Bears are really fast. You couldn't run away and you got sliced & diced.");
            }
    break;
    case 'PLAY DEAD':
        var smartBear = function(){
        smartBear = Math.random();
        }
        if (smartBear > 0.1){
            console.log("Bear got bored and left you alone. You saved yoursef from the mighty BEAR!");
        }
        else {
            console.log("Polar bears are smart. You couldn't fool him and you got sliced & diced.");
            }                
    break;
    default :
    console.log("You didn't act fast enough so you got sliced & diced"); 
    }



#2

Your code looks fine for the most part.

("Headshot! You have saved yourself and defeated the mighty BEAR!");

This won’t do anything on its own and needs a console.log in front of it if you want to display it in the console.

var smartBear = function(){ smartBear = Math.random(); }

Is easier to write as : var smartBear = Math.random();


#3

Thank you so much. Finally it works as it was planned! Dunno what I was doing back then with it heh.


#4

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