Learn Basic JavaScript by Building a Role Playing Game step 142

Hey guys, what the problem ? my code is :

} else if (monsterHealth <= 0) {
    if (fighting === 2) {
      winGame();
    } else { 
      defeatMonster();
  }
}

and then i press to check my code nothing is happining

Please provide the link to the challenge you are working on.

This happens when there is a syntax error

based on the code example you provided you are missing a curly brace at the end

yeah there is a curly brace at the end, i just dont repeat it here,fix now, but its still not working.

You will still need to provide revised full code and link to challenge so we can test it on our end

there is the link, and my code is:

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText += " You attack it with your " + weapons[currentWeapon].name + ".";
  health -= monsters[fighting].level;
  monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1;
  healthText.innerText = health;
  monsterHealthText.innerText = monsterHealth;
  if (health <= 0) {
    lose();
  } else if (monsterHealth <= 0) {
    if (fighting === 2) {
       winGame();
    } else { 
      defeatMonster();
  }
}

you need to be really sure of the closing brackets, you need to close the if, the else if and then the function

Your missing the closing curly brace for the attack function

add that in, then it will pass

ohh,thanks :smiley: and one more question, how do u make a table of that code then editing my text?

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like