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

Tell us what’s happening:

I really don’t understand how this is not correct. Can someone explain what it’s happening?

Sorry, your code does not pass. Hang in there.
You should check if fighting is equal to 2.

### Your code so far

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;
  health <= 0 ? lose() :
  monsterHealth <= 0 ? (fighting === 2 ? winGame() : defeatMonster(fighting < 2))
}

Your browser information:

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

Challenge Information:

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

HI @vlpureq !

They only want this part to change to a ternary.

The correct structure should be this

  if (health <= 0) {
    lose();
  } else if (monsterHealth <= 0) {
   //  ternary goes here to replace the existing if else statement 
  }
1 Like

That makes sense! Thank you for the help, it works now.

1 Like