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

Tell us what’s happening:

Basically, I’m supposed to “[…] wrap all of the code in the buyWeapon function inside another if statement […]”. Technically that’s what I’ve done here, but I keep getting an error that says: “You should have a new if statement that checks if currentWeapon is less than 3.”

And, not unlike the if statement itself—, I can’t quite wrap my head around this. Any type of help is appreciated.

The line of code in question:

function buyWeapon() {
  if (currentWeapon <= 3) {
  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.";
  }
  } 
}

PS: Apparently it was too much code for the post, so I only included this very function. If it is recommended for me to add more code, please instruct me on the best way to do so.

Browser information:

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

Challenge Information:

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

It says less than not less than or equal to

1 Like

okay that was a huge oversight on my part lmao, thanks for the answer, that was exactly what i needed!