Section 2 of Dragon Slayer


I have input the following code:

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random() * 5 + 2);
var totalDamage = 0;
while(slaying === true){
    slaying = false;
if(youHit = 1){
    console.log("You hit the dragon");
    totalDamage += damageThisRound;
if(totalDamage >= 4){
    console.log("The dragon is dead");
    slaying = false;
    console.log("The Dragon kills you, bad luck");

and when I run it, it comes up saying "It looks like you did not set slaying to true". As far as I can see, I declared slaying as true at the beginning. When I've changed the other slaying options to true, its caused the window to crash.

I've also copied code from Section 1 which passes on section 1 but when input into section 2, it also displays the message as said above.

What am I doing wrong?


I guess your too far in the game at the moment, meaning that the exercise probably just expects you to have the first 4 lines where slaying should be true. But you already have parts of the game where it gets set to false.

PS: Also keep think about whether it makes sense to have your conditionals outside of the loop and whether this condition:

youHit = 1

will actually do what you suppose it to do :slight_smile:


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