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

Tell us what’s happening:

How do we call a function isMonsterHit with an if statement if we have not stated the function in the code previously?

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[currentWeaponIndex].name + ".";
  health -= getMonsterAttackValue(monsters[fighting].level);
  if () {isMonsterHit};

  monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;
  healthText.innerText = health;
  monsterHealthText.innerText = monsterHealth;
  if (health <= 0) {
    lose();
  } else if (monsterHealth <= 0) {
    if (fighting === 2) {
      winGame();
    } else {
      defeatMonster();
    }
  }
}

// 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/125.0.0.0 Safari/537.36 Edg/125.0.0.0

Challenge Information:

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

you can call a function even if it doesn’t exist yet, you just need to create it soon after or nothing will work. The following steps I bet will be about creating that function

you are asked to call the isMonsterHit function in the condition (so in the round parenthesis of the if statement)

Find line of code that updates the monsterHealth variable. Place it within an if block. The block is the curly braces {} with a condition in the round brackets () that calls the isMonsterHit function. When calling a function , you have to use round brackets () directly after the name of the function.

you should replace the code

if () {isMonsterHit};

equals if (isMonsterHit()) {monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;}