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

Tell us what’s happening: I’m stuck but I’m sure I have the right code…?

Your code so far

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

### Your browser information:

User Agent is: <code>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</code>

### Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 119
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-basic-javascript-by-building-a-role-playing-game/step-119

My Code:

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

You’re close.

you are using the wrong operator here though

What your current line of code is doing is replacing the text with

what you want to do instead is add to the text.

that is where you can use the compound assignment operator

Hint: you used this operator on line 133 of this project

1 Like