Says it works but really it doesn't


#1

So I've ran my code trying my three variables "run, kick, & punch" and it appears the only one working right is run. Can someone take a look at my code and see where I've made a mistake, thanks.


var user = prompt("You are walking through a jungle and get surrounded by an angry tribe. What do you do? Run, Fight, or Scream","Type your answer here").toLowerCase();

switch(user){
    case 'run':
        var right = prompt("Do you go left or right?");
        if (right === right){
        console.log("You're too slow and are caught by the angry tribe");
        }
        else{
            console.log("You get away from the angry tribe");
        }
        break;
    case 'fight':
        var punch = prompt("Do you throw a rock, a punch, or a kick?").toLowerCase();
        if(punch === rock||punch === kick){
                console.log("You have stunned a tribe member and the rest run away");
            }
            else{
        console.log("You're able to beat up a couple but are caught in the end");
            }
        break;
    case 'scream':
        var stop = prompt("Do you stop screaming? Yes or No").toLowerCase();
        if (stop === no){
            var jump = prompt("Do you jump up and down? Yes or No").toLowerCase();
            var wave = prompt("Do you wave your arms around? Yes or No").toLowerCase();
            if (jump&&wave === no){
        console.log("The tribe mistakes your actions for dancing & singing and join in.");
            }
            else{
                console.log("You're captured by the angry tribe and taken away");
            }
        }
        break;
    default:
    console.log("I don't recognize your choice. Please start again.");


#2

I've corrected the variable fight code. Now just need to fix the variable scream code.


#3

There are several places where you have forgotten to add " " around your strings. In the case above, it should be:

if (right === "right")

#4

Thanks Albion. I have now been able to get all scenarios to work correctly.


#5

The working code is as follows:
var user = prompt("You are walking through a jungle and get surrounded by an angry tribe. What do you do? Run, Fight, or Scream","Type your answer here").toLowerCase();

switch(user){
case 'run':
var turn = prompt("Do you go left or right?");
if (turn === "right"){
console.log("You're too slow and are caught by the angry tribe");
}
else{
console.log("You get away from the angry tribe");
}
break;
case 'fight':
var punch = prompt("Do you throw a rock, a punch, or a kick?").toLowerCase();
if(punch === "rock"||"kick"){
console.log("You have stunned a tribe member and the rest run away");
}
else{
console.log("You're able to beat up a couple but are caught in the end");
}
break;
case 'scream':
var stop = prompt("Do you stop screaming? Yes or No").toLowerCase();
if (stop === "no"){
var jump = prompt("Do you jump up and down? Yes or No").toLowerCase();
var wave = prompt("Do you wave your arms around? Yes or No").toLowerCase();
if (jump==="yes"&&wave==="yes"){
console.log("The tribe mistakes your actions for dancing & singing and join in.");
}
else{
console.log("You're captured by the angry tribe and taken away");
}
}
break;
default:
console.log("I don't recognize your choice. Please start again.");
}


#6

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