2/8 Dragonslayer: Declare your variables


#1

var slaying=true
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!");
totalDamage=+damageThisRound
if (totalDamage>=4) {
console.log("Dragon has fallen, now it is time to get the girl.");
slaying= true;
}else{
youHit=Math.floor(Math.random()*2);
}
} else {
console.log("You missed!");
}
slaying = true;
}

I keep getting a loop on this one, no matter what I do. When I change slaying to false here*
console.log("Dragon has fallen, now it is time to get the girl.");
slaying= true;

it tells me, oops, did you set slaying to true? But when I do this, I get a script crash/loop. I have tried every permutation here, or changing stuff around, from false to true to no success. HELP!


#2

putting far more code in the exercise then required can cause some serious trouble. Comment out everything after the declaration of totalDamage


#3

Be sure to write all the variables in var statements and end the lines with a semi-colon

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

In the following lessons you will construct the rest of the code. Keep in mind that when you get to this line, be sure to write the operator in the correct order:

    totalDamage += damageThisRound;

#4

After the dragon has fallen, wouldn't it be false that you are slaying? At no point are you setting slaying to false, so the loop keeps running as slaying always = true