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

Task:

On a new line, use the addition assignment operator(+= ), to add the string " You attack it with your <weapon>." to the text value, replacing <weapon> with the player’s current weapon. Additionally, remember that this line of text starts with a space so it will properly display.

Code:

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

WARNING:

You should use dot notation to access the innerText property of text on a new line.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36

Challenge Information:

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

Welcome to the forum @limbostory

Here is your code:

Just a few fix ups needed here.

  1. the instructions want you to use compound assignment, which you added on the second line
  2. the code needs to be one line.

At the moment, the second text.innerText assignment will overwrite the first one.

So place the plus sign before the equals sign with the string that begins You attack ...
Concatenate the third line in the function onto the second line.
At the end of the string after weapons concatenate a dot, nested in quote marks.

Happy coding

1 Like

Thank you very much for your help! I really appreciate it!

1 Like

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