4.The first 'if' statement MESSAGE ERROR


So I write the code below:

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

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.


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.


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;


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


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


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