Dragon: set slaying to true


#1

I have altered this code dozens of times, reset my browser frequently, all to no avail. Show me where I am off, please.

here is my code:


#2

Hi your code should have that steucture

while (condition) { #open the while statement
    if (considtion) {#open the first if statement 
        if (consiton) { #open the second if statement

        }#close the second if statement
        else { #open the first else statement 

        }#close the first else statement
    }#close the first if stastement
    else {#open the second else statement

    }#close the second else statement

}#close the while statement

#3

wizmarco,
What is the purpose of the other "else" statement? Either youHit and kill; or youHit, damage, and you get killed. I don't understand the other "else" statement.
clarify please,
lodum


#4

Hi like you can see we have two if statement and two else statement.
First they aske you to put an if and esle statement in lesson Lesson 4. In the Next lesson they aske you to create anif and else statement inside the if statement.
its word like that

1 The First if and else statement:

if (youHit) {
    console.log("Here go your message")
}
esle {
    console.log("The other message")
}

In this case if youHit is 1 (true) the first message will show up otherwise if it's 0 (false) the second message will.

  1. the if and else statement inside the first if statement

if (youHit) { 
        console.log("You hit the dragon!");
        totalDamage += damageThisRound;
        
        if (totalDamage >= 4 ) {
            console.log("You slew the dragon");
            slaying = false;
        }
        else {
            youHit = Math.floor(Math.random() * 2);    
        }
    }
    else {   
        console.log("the dragon defeated you!")
        slaying = false
    }

in this case they aske you to put the new if and else statement so it will work only when youHit its 1 (true).
when its true we have the sum of damgeThisRound to totalDamage

totalDamage += damageThisRound;

then it run the if statement

 if (totalDamage >= 4 ) {
            console.log("You slew the dragon");
            slaying = false;
}

like you can see we have a conditionif totalDamage is greater or equal than 4 it will print the congratulation message and put slaying to false and stop the while loop.

But if totalDamage is less than 4 it will run

youHit = Math.floor(Math.random() * 2);

It will assigned a new random 1 or 0.

2 in case if the YouHit is equal to 0 (false)

It will run this else statement

else {   
        console.log("the dragon defeated you!")
        slaying = false
}

Hope that could Help You


#5

Thank you. Your explanation clarified my thinking.