4.The first 'if' statement MESSAGE ERROR


#1



So I write the code below:

while(slaying) {
    if(yourHit) {
        console.log("You won!");
    } else {
            console.log("You lost!");
        }
    slaying=false;
}

Oops, try again. Make sure you log a message to the console to let the player knows if (s)he won or lost!

Has anybody a slight Idea wtf did I do wrong ? Thanks everyone in advance.


#2

Im going to give you a hint:

Make Sure you define your variables, like slaying, yourHit,etc... Should have been done by previous exercice but your code dosent show that.


#3

I have the same error, my code is:

var slaying = false;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;

while(slaying) {
    if (youHit) {
        console.log("You hit!");
    } else {
        console.log("You missed!");
    }
    slaying = false;
}

#4

OK, I know.
var slaying = true not false :slight_smile:


#5

This is very confusing, as the previous exercise specifically tells you to set Slaying = false


#6

Make the boolean 'slaying' true. I had the same error and doing that fixed it.