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

Tell us what’s happening:

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

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

Your browser information:

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

Challenge Information:

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

i need to know how to use += symbol specified here. please write the correct code

Hi @gideonihonre345

  1. You need to use compound assignment using augmented addition, otherwise the previous text will get over written.
  2. Add a single space after the colon.

Happy coding

text.innerText = "You now have a " + newWeapon + ".";
inventory.push(newWeapon);
text.innerText += " In your inventory you have: " ;

The order of your last three lines needed to be changed also. You will not be able to later display the new weapon until you push it into the inventory array. Displaying the full inventory is the next step (Step - 92).

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