Dragon Slayer - no hit damage


#1

Hi everyone. I'm having trouble with hit damage against the dragon, though the program says I've done everything right and can continue. What is being logged to the screen every time is "You hit the dragon!
false"

So I'm hitting the dragon but there is no indication for damage dealt or anything like that.
Here is my code:

// Variables

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

/* While loop to check if slaying is still true, or basically that slaying is still going, i.e. dragon is still being attacked */

while(slaying)
{
if(youHit)
{
console.log("You hit the dragon!");
totalDamage = totalDamage + damageThisRound;
/* This could be written as
totalDamage += damageThisRound */
if(totalDamage >= 4)
{
console.log("You have slayed the dragon!")
slaying = false;
}
else
{
youHit = Math.floor(Math.random() * 2);
}
}
else
{
console.log("You missed and the dragon killed you. You lose.");
}

slaying = false;

}

I've checked my code with the code of the game that they gave at the beginning and I think it's identical aside from some structure and comments. Can anyone tell what I'm doing wrong? Thanks so much in advance!


#2

I think I fixed it.
I had "Math.random" instead of "Math.random()" for the 3rd variable.

Also, is there any (relatively simple) way to log the remaining health of the dragon? Thanks!


#3

Dang it, I just realized that I could do less than 5 damage and the game still ends.

Any Idea what to do to fix that?


#4

EVERYONE IGNORE THIS! I'LL BE WRITING ANOTHER POSTS THAT DETAILS THE REMAINING PROBLEMS AND OMITS THE OLD.

thanks