Dragon slayer issue


#1

Hi I decided to add a bit to the end product, and I can't seem to get it to run. Any help is appreciated.

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

var ready = prompt("Are you ready to slay a dragon?");
if(ready === "yes") {
console.log("You begin fighting the dragon.");
} else {
console.log("take your time.");
}

while(slaying) {
if (youHit) {
console.log("You hit the Dragon for" + " " + damageThisRound + " " + "damage!");
totalDamage += damageThisRound;
if (totalDamage >= 4) {
console.log("You have destroyed the Dragon!");
slaying = false;
slaying2 = true;
totalDamage = 0;
while(slaying2) {
if (youHit) {
console.log("You hit the Dragon for" + " " + damageThisRound + " " + "damage!");
totalDamage += damageThisRound;
if(totalDamage >= 10) {
console.log("You are the ultimate dragon slayer!!");
slaying2 = false;
} else {
youHit = Math.floor(Math.random() * 5);
}

                    } else {
                        console.log("Your sword misses the dragon and he burns you to dust.");
                        slaying2 = false;
                    }


} else { 
    youHit = Math.floor(Math.random() * 5);
}

}
else
{
    console.log("Your sword misses the dragon and he burns you to dust.");
    slaying = false;
}

}
}


#2

@webjumper49018,

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

var ready = prompt("Are you ready to slay a dragon?");
if(ready === "yes") {
    console.log("You begin fighting the dragon.");
} else {
   console.log("take your time.");
}

while(slaying) {
  if (youHit) {
    console.log("You hit the Dragon for" + " " + 
                 damageThisRound + " " + "damage!");
    totalDamage += damageThisRound;
    if (totalDamage >= 4) {
         console.log("You have destroyed the Dragon!");
         slaying = false;
         slaying2 = true;
         totalDamage = 0;

         while(slaying2) {
            if (youHit) {
                console.log("You hit the Dragon for" + " " + 
                                       damageThisRound + " " + "damage!");
                totalDamage += damageThisRound;
                if(totalDamage >= 10) {
                    console.log("You are the ultimate dragon slayer!!");
                    slaying2 = false;
                } 
                else {
                    youHit = Math.floor(Math.random() * 5);
               }
            } 
            else {
                console.log("Your sword misses the dragon and he burns you to dust.");
                slaying2 = false;
            }
         }//<<<<<Missing closing the WHILE-loop

    }  
    else { 
        youHit = Math.floor(Math.random() * 5);
    }

  }
  else {
    console.log("Your sword misses the dragon and he burns you to dust.");
    slaying = false;
  }

}
//}  //unidentified flying curly-bracket UFCB

#3

Thanks, I already fixed it by typing it again, but I understand where i messed up now.