Dragon Slayer! Declare your variables


#1

I apologize as it didn't copy and paste over quite as pretty as I wanted. I am having an issue with my code, no matter what I change I keep getting the same error code "You didn't set slaying = to true" or it turns into an infinite loop. Hopefully someone can shed some insight on my error. Thanks

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

while(slaying) {
slaying = false;
if(youHit===1) {
console.log("You got the dragon!");
totalDamage += damageThisRound;
} if(totalDamage >=4) {
console.log("The dragon is dead!");
slaying = true;
} else {
console.log("The dragon fried you!");
}
}


#2

nevermind, figured out what was wrong.


#3

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