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

In the solution to this step of building the role playing game I have:

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText += "You attack it with your " + inventory[currentWeapon] + ".";
}

and it doesn’t pass. I’ve also tried:

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText += "You attack it with your " + weapons[currentWeapon].name + ".";
}

I don’t know if the method i’m using to get the player’s current weapon is the problem. The hint given when I fail this is not very helpful. Please help me. I’m stuck.

1 Like

what is the link to the step?

what is the hint you are given?

link: Learn Basic JavaScript by Building a Role Playing Game: Step 120 | freeCodeCamp.org

hint: You should add the string You attack it with your to the text.innerText value. Remember that spacing matters.

1 Like

you also need a space at the beginning to have a space after the period at the end of the other text you added

2 Likes

Wow…can’t believe that was the problem the whole time. Thanks a lot

1 Like

Why is += needed in this case?

hey there, I suggest opening your own topic to ask for help!

I have faced a problem in this step. Now it is solved after reading this post.