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

Where is the mistake guys

function buyWeapon() {
if (gold >= 30) {
gold -= 30;
currentWeapon++;
goldText.innerText = gold;
let newWeapon = weapons[currentWeapon].name;
text.innerText += " In your inventory you have: " + newWeapon + β€œ.”;
inventory.push(newWeapon);

}
}

Welcome to the forum @ahmedbouhrira365

You replaced the existing text.innerText variable.
The instructions want you to add your code on a new line.

Happy coding

1 Like

The issue in your code appears to be with the string concatenation in the line:

text.innerText += " In your inventory you have: " + newWeapon + β€œ.”;

It seems you’re using curly quotes β€œβ€ around the period at the end of the line, which might be causing a syntax error.

Replace the curly quotes with straight quotes ":

text.innerText += " In your inventory you have: " + newWeapon + ".";

After making this change, your function should work correctly.

2 Likes

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