Question 4


#1

Don't know whats wrong with this code. can anyone help?
Thank you.

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

while(slaying){
if(youHit) = 1 {
console.log("Congratulaions! You hit the Dragon");
}
else{
console.log("The Dragon has defeated you");

slaying = false;
}


#2

@perezwillz,
You are forgetting a closing-curly-bracket-}
for your ELSE-statement

else{
 console.log("The Dragon has defeated you");
}

#3

Thanks but i still failed it after the correction

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

while(slaying){
if(youHit) = 1 {
console.log("Congratulaions! You hit the Dragon");
}
else{
console.log("The Dragon has defeated you");
}

slaying = false;
}


#4

@perezwillz,
What kind of condition testing iss this ????


#5

Please read the if documentation here.


#6

i wrote if(youHit){
whats wrong with it?


#7

Ok I got it! I should have just put the equation inside the bracket


#8

@perezwillz,
you have to use a comparison....