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

Tell us what’s happening: Objective: Step 117

Now, set the innerText property of monsterName to be the name property of the current monster. Do the same for monsterHealthText and the health property.

Your code so far

My code so far:

function goFight() {
  update(locations[3]);
  monsterHealth = monsters[fighting].health;
  monsterStats.style.display = "block";
  innerText.monsterName = "name";
  innerText.monsterHealthText = "health";
}

It’s telling me " You should use dot notation to access the innerText property of monsterName ."

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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 117

It looks like the syntax here is incorrect

take a close look at the correct syntax your wrote earlier for the innerText property.

text.innerText = "Don't sell your only weapon!";

Once you resolve then you will need to get the correct name for the monster.

You will need to fix this part

You should not have a hardcoded string of name.

You will need to access the name from the monsters array.

This is the monsters array

const monsters = [
  {
    name: "slime",
    level: 2,
    health: 15
  },
  {
    name: "fanged beast",
    level: 8,
    health: 60
  },
  {
    name: "dragon",
    level: 20,
    health: 300
  }
]

If you wanted to access the level of the current monster, you would write this.

monsters[fighting].level

The lesson wants you to access the current name.
So follow that same syntax but for the name.

Lastly, you will need to fix this part

Instead of the string health, it should be the monster health variable you created earlier.

once you fix those issues, then the test will pass

1 Like

Thank you very much!

I’m still stuck.

Now my code is:

  update(locations[3]);
  monsterHealth = monsters[fighting].health;
  monsterStats.style.display = "block";
  monsterName = monsters[fighting].name;
  text.innerText = monsterName;
  text.innerText = monsterHealth;
}

This is correct, but you shouldn’t assign it to monsterName like this

instead replace monsterName here with monsters[fighting].name

 text.innerText = monsterName;

Once you fix that, you will need to fix this

The reason why I showed you the text.innerText was because you have syntax errors here with innerText.monsterName and innerText.monsterHealthText

You need to update the text.innerText to instead say monster name followed by innerText and monster health text followed by innerText so the syntax is correct.

hope that clearer

As a sidenote, it looks like a lot of beginners are struggling with understanding how the monsters array works and how to access information from it.

I am creating some issues now to show some more code examples and better hints to help out beginners

monsterName.innerText = monsters[fighting].name;
monsterHealthText.innerText = monsters[fighting].health;

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.