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

Tell us what’s happening:

I dont know what is wrong.

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() : (monsterHealth <= 0) ? defeatMonster() : null);
}

Sorry, your code does not pass. Don’t give up.

You should check if fighting is equal to 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

What was the last hint given to you?

You are only asked to change the nested if/else to use a ternary.

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

Example:

condition === 42 ? fn1() : fn2();
1 Like