2nd if statement


#1



Second if statement


SyntaxError: Unexpected token {
help please.


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

var slaying = true;

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


#2

Try adding another closing brace at the end: }


#3

remove
else(youHit)
because you ve already taken if(youHit)
if(youHit) means if(youHit==true)

so how could it be possible same condition for both?

if (/* Some condition */) {
// Do something }
else if (/* Some other condition */) {
// Do something else }
else{
// Otherwise // Do a third thing
}

@jibblyj


#4

i have tried it and it is not working.


#5

funny thing is, if you hit the hint button it says your code should look like this

while (slaying) {
  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;
  }
}