The second 'if' statement


#1

var slaying = true;
while(slaying) {
slaying = false;
}

var youHit = Math.floor(Math.random() * 2);
if(youHit) {
console.log("You hit!");
totalDamage += damageThisRound;
if(totalDamage >= 4) {
console.log("You win!");
slaying = false;
} else {
youHit = Math.floor(Math.random() * 2);
}
else {
console.log("You lose!");
slaying = false;
} else {
console.log("You missed!");
}
slaying = false;
}

var damageThisRound = Math.floor(Math.random() * 5 + 1);

var totalDamage = 0;

In the this block caught in curly braces, please help to understand ?


#2

What part of the code is giving you trouble?


#3

Write Unexpected token else


#4

Please post your written code because it is easier for us to correct and refer for you. :slight_smile:


#5

var youHit = Math.floor(Math.random() * 2);
if(youHit) {
console.log("You hit!");
totalDamage += damageThisRound;
if(totalDamage >= 4) {
console.log("You win!");
slaying = false;
} else {
youHit = Math.floor(Math.random() * 2);
}
else {
console.log("You lose!");
slaying = false;
} else {
console.log("You missed!");
}
slaying = false;
}


#6

Your code is all over the place for starters you need to compile it according to the order of each exercise.

So,
Global variables first.
Then everything should be nested in your while loop, not separately.


#7

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