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

Tell us what’s happening:

My code is failing and I can’t spot where/why it fails:
if (monsterHealth <= 0) {
if (fighting === 2) {
winGame();
} else {
defeatMonster();
}
}

The console msg:
You should add a new if statement in your else if block.
Your new if statement should check if fighting is strictly equal to 2.
You should call the winGame function in your if block.
You should add an else block.
Your else block should call the defeatMonster function.

Your code so far

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

/* file: styles.css */

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

function attack() {
  if (health <= 0) {
    lose();
  }

  text.innerText = "You attack the " + monsters[fighting].name + " with your " + weapons[currentWeaponIndex].name + ".";
  
  monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;
  monsterHealthText.innerText = monsterHealth;

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

  health -= monsters[fighting].level;
  healthText.innerText = health;

  if (health <= 0) {
    lose();
  } else {
    text.innerText += " The " + monsters[fighting].name + " attacks you.";
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0

Challenge Information:

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

reset the step and follow the instructions:

Back to your attack function - inside the else if block,

I don’t see the else if block anywhere in your code

I think it is the ‘user editable’ section which is above your comment. If not then IDK what to say/do/wish.

here ya go, this in the above post

Closed. I don’t want help.