4. The first 'if' statement


#1

Can you guys help me? When I press "Save & Sumbit Code" it appears: "Oops, try again. Make sure you log a message to the console to let the player knows if (s)he won or lost!"


#2

@cssrunner13664,
In short::
As your slaying variable is set to false
you will not enter into the while loop......

Long explanation::

In section-3 The 'while' loop
you would have the code

var slaying=true;
var youHit=Math.floor(Math.random()*2);
var ThisRound=Math.floor(Math.random()*5+1);
var totalDamage=0;
while(slaying)
{
    slaying=false;
}

It is in this configuration you will have to add the IF ELSE statement
like

var slaying=true;
var youHit=Math.floor(Math.random()*2);
var ThisRound=Math.floor(Math.random()*5+1);
var totalDamage=0;
while(slaying)
{
    if (condition) {
        //IF code-block
    else {
        //ELSE code-block
    }
    slaying=false;
}

#3

This tripped me up, too. At first, I set slaying to "True" but that, obviously, results in an infinite loop. I actually figured it out moments before I began this response. :grin:


#4

Thanks CSSrunner for your explanation !
For me the word "false" appears in the editor page with the "congratulations " or the "dragon defeated you" sentence . Is that normal ?


#5

Can't believe I couldn't see that. Thanks! :cold_sweat: