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

Tell us what’s happening:

why i am getting the following message; You should assign the string The to innerText property of text.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

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

// User Editable Region

Your browser information:

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

Challenge Information:

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

You always need to use template literals when you are asked to create a string with a variable in it. (Template literals use backticks and not double quotes)

you need to wrap The in quotes, before the +. Here you are not concatenating anything because + is part of the string instead of being between strings

1 Like

You didn’t close quotes after the first word, or open quotes before your last words. Remember spacing in the words as instructed.

You also have an error in the first bit of your monster name code. Look how the variable is defined earlier on in the code.

Tell us what’s happening:

why am i getting the following message;You should assign the string The to innerText property of text.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

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

// User Editable Region

Your browser information:

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

Challenge Information:

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

You need spaces in there

the required string is "The " with a space before the closing quote

Also give a space between quote mark " and the word attacks.

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