Learn Basic JavaScript by Building a Role Playing Game - Step 153

Tell us what’s happening:

always getting syntax error eventhough i havent changed the code
“SyntaxError: unknown: Unexpected token (242:1) 240 | xpText.innerText = xp; 241 | goTown(); > 242 | } | ^”

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

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

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 OPR/107.0.0.0

Challenge Information:

Learn Basic JavaScript by Building a Role Playing Game - Step 153

Hello and welcome to the forum;
lets try to understand why this app get angry and throw an error together :slightly_smiling_face:

First of all, a SyntaxError means some syntax is written incorrectly. If we continue, it shows which line and which text has an error, but it shows the last line of the code block and nothing wrong on there. If JavaScript throws an error on the last line, mostly this means there is a missing or extra bracket. That is mean some function is not closed or main fuction closed early before the code block end.

If you follow each curly bracket, which is not easy sometimes, or you can undo your action with reset, you will notice the function attack() curly brackets are not closed.

So, as a result, if you add one curly bracket at the right point, this error will disappear.

Happy coding.