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

Tell us what’s happening: i didnt understand what code is to add in these step

Your code so far

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText += " You attack it with your " + weapons[currentWeapon].name + ".";
  health -= getMonsterAttackValue(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) {
    fighting === 2 ? winGame() : defeatMonster();
  }
}

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 149

Share the error please

Okay so in front of you is an attack function. Right in that free line below the health variable, create an if statement. The condition should be a call to the isMonsterHit function.

Let me know if I need to explain that any further. :slight_smile:

I think the solution goes like this:

if (xyz) {
    isMonsterHit();
  };

But I don’t know what “xyz” inside if () should be. Maybe I’m forgetting or miswriting part of the code. Can you please explain? Thank you :slight_smile:

The return value from isMonsterHit() is the conditional value (the function doesn’t exist yet).

Example:

if (isEven()) {
  // do something when even
}
2 Likes