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

Tell us what’s happening:

The following function should add the value of newWeapon to the inventory array. and actually its does it. But I can not pass the test

Your code so far

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

/* file: styles.css */

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

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



// User Editable Region

Your browser information:

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

Challenge Information:

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

Back at the beginning of this project, you created the inventory array. Add the newWeapon to the end of the inventory array using the push() method.

Why have you added this line of code?

mea culpa. thank you

1 Like