I got the problem correct but why the last "youHit = Math.floor(Math.random() * 1)" what is the purpose


#1


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

while(slaying){
    console.log("you're trying to attack me the great Dragon")
    slaying = false
}
if(youHit = 1){
    console.log("A puny human has drawn blood")
}else{
    console.log("As expected you are nothing to me, I wasn't even trying and you've crumbled")
}
 totalDamage += damageThisRound;
 if(totalDamage >= 4){
     console.log("Noooo....Noooo, a human has slayed me, the great Zaractu")
     console.log("A voice echoes from the shadows, this is not over, it will\
never be over this world is mine")
     slaying = false
}else{
    youHit = Math.floor(Math.random() * 1)
    console.log("Do you see this, people of Azra. Now take this as lesson\
and remain under foot")
}



Replace this line with your code. 



#2

it should be times two:

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

this way, you have a 50% change to hit again. Or miss.


#3

while(slaying){
    console.log("you're trying to attack me the great Dragon")
    slaying = false
}

Also keep in mind that the whole game should take place in the while loop (yours ends pretty fast), so that slaying =false marks the end of the game. And also be careful with these kind of conditions:

if(youHit = 1){

here you assign 1 to youHit changing it's value and using an effective value of 1 for the condition. As 1 has a truth value of true you'll always pick this path regardless of the value of youHit. So better use == or === to compare values.


#4

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