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

Hey everyone, kindly walk me through this, my code and instruction are below;

function buyWeapon() {
  if (currentWeapon < weapons.length - 1) {
    if (gold >= 30) {
      gold -= 30;
      currentWeapon++;
      goldText.innerText = gold;
      let newWeapon = weapons[currentWeapon].name;
      text.innerText = "You now have a " + newWeapon + ".";
      inventory.push(newWeapon);
      text.innerText += " In your inventory you have: " + inventory;
    } else {
      text.innerText = "You do not have enough gold to buy a weapon.";
    }
  } else {
    text.innerText = "You already have the most powerful weapon!";
  }
  button2.innerText = location["Sell weapon for 15 gold"][1];
  button2.onclick = location["sellWeapon"][1];
}

The instruction is below;
Once a player has the most powerful weapon, you can give them the ability to sell their old weapons.

In the outer else statement, set button2.innerText to Sell weapon for 15 gold. Also set button2.onclick to the function name sellWeapon.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15

Challenge Information:

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

Hi! A couple things here. First, you need to put the new code within the second (outer) else brackets. Second, reread the instructions for what you will put after each equal sign. (Hint, does it make sense to have locations named with the text you put in? We aren’t looking to modify locations in this step. )

1 Like

Appreciate!!! Got it!!!

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