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

Tell us what’s happening:

i believed i have followed through answering the question with the use of push on initially declared inventory. however, my code has yet to pass and am confused if it’s an issue with the scope of declaration which i believe is in the global scope! i had also tried to append this code immediately under line 8, just beneath the declaration of inventory !

Your code so far

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

/* file: styles.css */

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

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    goldText.innerText = gold;
    let newWeapon = weapons[currentWeaponIndex].name;
    text.innerText = "You now have a " + newWeapon + ".";

// 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/ Safari/537.36 Edg/

Challenge Information:

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

There are 2 problems with this line:

  • newWeapon is a variable, not a string. So remove the double quotes around it.
  • You have to put this line inside the if statement in the buyWeapon function
1 Like

As the other user said,

you need to write: inventory.push(newWeapon) and you need to type it within the if statement of the buyWeapon function. The mistake you made is you have added ‘’ " which treats it as a string, secondly you declared it outside the function itself.

1 Like

Thank you for your assistance.

Thank you for your feedback.