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

Tell us what’s happening:

Your code so far

function attack() {
text.innerText = "The " + monsters[fighting].name + " attacks. ";
}

error
** You should use the concatenation operator to add the string attacks.to the**
monsters[fighting].name string.

Step 117

Now you can build the attack function. First, update the text message to say "The <monster name> attacks.", replacing <monster name> with the name of the monster. Remember you can use the concatenation operator for this.

but still showing error i dont know what is the problem in this code…pls some one tell me. let me correct it…

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 117

The error message suggests that you should use the concatenation operator to combine the string “attacks” with the name of the monster.

In JavaScript, the concatenation operator is +. If you’re already using + to concatenate strings in your code, the issue might be elsewhere. However, to address the error message directly, you can rewrite the attack() function like this:

function attack() {
text.innerText = “The " + monsters[fighting].name + " attacks.”;
}

This will properly concatenate the strings without triggering the error. Make sure text and monsters are properly defined elsewhere in your code.

remove the space at the end

1 Like

thanks it works. thank you so much

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