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

Tell us what’s happening: 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.

I can’t figure this step out. I have been at it for a few days now. Please help.

### Your code so far

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

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

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 118

You are technically doing what the instructions are asking, just not in the way they want you to do it. Pay attention to the last line of the hint:

“Remember that you assigned this value to a monsterHealth variable.”

In other words, they want you to use the variable you already created to store the monster’s health in.

So am I supposed to use "const " or “let”? That doesn’t seem right

I think perhaps my last hint didn’t come across as I had hoped. This has nothing to do with const or let. Look at all the code already in the goFight function. Do you see where you saved of the monster’s health in a variable near the beginning of the function? The tests want you to use that variable to set the innerText for the monster’s health.

When I submit… innerText.monsterHealthText = monsters[fighting].health;

The response is… You should use dot notation to access the innerText property of monsterHealthText .

I’m not understanding

Look at the code near the beginning of this function. Didn’t you already save this value to a variable? The tests want you to use the variable to set the innerText.

Let me repeat, the code you originally pasted at the beginning is technically correct. It’s just that you are not assigning innerText in the last line exactly the way the tests want you to. They don’t want you to use monsters[fighting].health. They want you to use the variable that you saved that value to earlier in the function.

So, in the beginning of the code is… monsterHealth = monsters[fighting].health;
They’re not wanting me to use… monsters[fighting].health; as the value since it is already used. Okay I understand that.

The variable is… monsterHealth, correct?

I submitted… monsterHealth = innerText.health;
Not correct. I will be glad once I move from this step.

Ya, innerText can’t be used by itself. It is a property of an element.

Look at how you set the innerText for the monster’s name:

monsterName.innerText = monsters[fighting].name;

That’s how you would do it for the monster’s health text as well.

Again, the problem is on the right side of the equals sign. You need to use the variable that already contains the monster’s health.

I’ll repeat again, the original code you submitted is technically correct. The only issue is that you need to use the variable that already has the monster’s health instead of using monsters[fighting].health explicitly in the last line. That’s the only change you should make to your original code.

Got it. Figured it out. Thank you so much for sticking with me!

1 Like

Hello There,
Here’s how you accomplish the task by using the dot notation method:

  1. To set the **innerText** property of **monsterName** to be the name property of the current monster:
monsterName.innerText = monsters[fighting].name;
  1. To do the same for **monsterHealthText** and the **health** property.
monsterHealthText.innerText = monsters[fighting].name;

Happy Coding Code Ninjas! :cat:‍:rocket::ok_hand: