text.innerText += “Right! You win 20 gold!”;
goldText.innerText += 20;
The response is ‘You should use compound assignment to add the string “Right! You win 20 gold!” to the end of text.innerText’
Can someone please tell me where I might be going wrong? Thanking you
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
function pick(guess) {
const numbers = [];
while (numbers.length < 10) {
numbers.push(Math.floor(Math.random() * 11));
}
text.innerText = "You picked " + guess + ". Here are the random numbers:\n";
for (let i = 0; i < 10; i++) {
text.innerText += numbers[i] + "\n";
}
if (numbers.includes(guess)) {
text.innerText += "Right! You win 20 gold!";
goldText.innerText += 20;
}
}
}
// 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 Edg/126.0.0.0
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 170
The first one is good. It then asks for 2 things.
Add 20 to the value of gold. “gold” is defined as a variable at the start of the code. You need to add 20 to that.
Then it asks you to update the inner text of goldText. If you look at your code above, goldText links to the index html text. The user interface which has the gold score. You also need to update that . You don’t add 20 manually. In the previous step you have updated the gold so refer to that.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.