# Confused

#1

Will the damage I deal to the dragon always be the same everytime it loops and ends when they add up to 4 or higher?
damageThisRound already stored a random number right?

``````var slaying = true;
// A bit of new math magic to calculate the odds
// of hitting the dragon. We'll cover this soon!
var 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 the dragon and did " + damageThisRound + " damage!");
totalDamage += damageThisRound;

if (totalDamage >= 4) {
console.log("You did it! You slew the dragon!");
slaying = false;
} else {
youHit = Math.floor(Math.random() * 2);
}
} else {
console.log("The dragon burninates you! You're toast.");
slaying = false;
}
}``````

#2

you could update damageThisRound:

``````else {
youHit = Math.floor(Math.random() * 2);
# update damage this round here
}``````

then you determine again if you get a second (or third, fourth or fifth) hit, and you calculate new damage so the damage isn't the same every round

#3

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