Help me polish my Dragon Slayer game!


Dragon Slayer Final Result
Hey guys! I've completed the exercise but have found that theres a simple problem. My console shows "You spanked him" even when we've lost the battle. (Why i added "oh no") How can I fix this to only show I hit him when ive defeated him? Thank you!

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

var damageThisRound = Math.floor(Math.random()*5 + 1);

var totalDamage = 0

var slaying = true;

while(slaying) {

 if (youHit) {
    console.log("You spanked him!")
    totalDamage += damageThisRound;
       if (totalDamage >= 4){
         console.log("The Big Bad Dragon moans, you use the distraction of ecstasy to escape!")
  slaying = false;
    } else { 
        youHit = Math.floor(Math.random() * 2);

} else {
    console.log("Oh no! Big Bad Daddy Dragon didnt like that! He cooked you up!");
      slaying = false;


Just remove this line?


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