I was learning javascript on Codecademy. Then all of a sudden I encountered the error "Oops, try again. Make sure you print a message onto the console!"
var slaying = true
var youHit = Math.floor(Math.random()* 2)
var damageThisRound = Math.floor(Math.random()*5 + 1)
var totalDamage = 0
var dragonSlaying = function() {
while(slaying){
if(youHit){
console.log("You hit that bastard");
totalDamage += damageThisRound;
if(totalDamage >= 4){
console.log("The dragon has been slain");
slaying = false;
} else {
youHit = Math.floor(Math.random() * 2);
}
} else {
console.log("You have been defeated; you missed the slimy thing! Maybe next time.");
slaying = false;
}
}
slaying = false;
}