Where did i screw up on the 1st if?


#1

it says that i need to console.log a message to state whether or not they won

slaying=false
youHit=Math.floor(Math.random() * 2)
damageThisRound=Math.floor(Math.random()*5 + 1)
totalDamage=0
while(slaying){
    if (youHit === true) {
        console.log("you win!");
    }else{
        console.log("dragon defeated you!");
    }
    slaying = false
}


#2

the while loop will never execute since you declare slaying on line 1 and set it to false, try setting to true

because the loop doesn't execute, nothing get logged to the console


#3

Well there are few problems in there.

  1. You don't use ; behind the code lines. (just a note)

Number 1 - true true in number equals to 1
Number 2 - false false in number equals to 0

With youHit=Math.floor(Math.random() * 2) you are saving number 0 or 1 on random in variable youHit so you can get true or false.

You set variable slaying to be false which won't even trigger the while loop because while will go while slayin is true.


#4

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