Dragon Slayer - 4/6 "Make sure you log a message to the console to let the player knows if (s)he won or lost!"


#1

I am struggling with this part. Please help!

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

while(slaying){
    if (youHit >= 4) {    
        console.log("You hit the dragon! You win!");
    }
    
    if (youHit) {    
    totalDamage += damageThisRound;
    console.log("You slayed the dragon!");
        
    } else {
        console.log("You have missed the dragon!");
    }
    slaying=false;
    
}

I keep getting the message:

Oops, try again. Make sure you log a message to the console to let the player knows if (s)he won or lost!


I know the first part is redundant in my 'If' statement...and that's because I'm not sure how to get it to pick up the player won...


#2

Just kidding... I figured it out..It literally wanted the words to say "you hit!" and "you miss!"

LAME! LOL


#3

Well, actually, no. At the beginning, slaying is equal to true. But to avoid an infinite loop, you have to change it to false later. Also, I didn't need it to say you hit and you missed. My messages were:
"You hit the dragon and did _____ damage!"
"Wow! Amazing! The dragon is slain."
and
"Ouch! The dragon incinerated you."
So it's not lame because you can personalize the messages. You must have corrected your error at the slaying variable part and changed the messages at the same time.


#4

Try this. I got a little carried away... lol

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

while (youHit <= 1)
{
totalDamage += damageThisRound;
youHit++;
}

if (youHit >= 1)
{
console.log("********************************")
console.log("A dragon appears with 4 HP!")
console.log("********************************")
console.log("You hit the dragon for...")
console.log(totalDamage + " " + "HP!")
}
if (totalDamage >= 4)
{
console.log("You slayed the dragon!")
}

else
{
youHit = Math.floor(Math.random() * 2);
console.log("However, the dragon attacks back with a fireball for..")
console.log(youHit + " " + "HP!!")
console.log("Your attack wasn't strong enough...")
console.log("You didn't slay the dragon...")
}