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

I can’t seem to figure out why this isn’t working. I’ve tried all the ways I know to.

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

It keeps saying " You should have a new if statement that checks if currentWeapon is less than 3 ."

Welcome to the forums.

“Wrap all of the code in your buyWeapon function inside another if statement.”

This doesn’t mean to wrap the entire function in an if statement, this means to wrap all of the code inside of the function in an if statement.

In the parenthesis of your if statement, you need to correct your comparison operator. The instructions ask you to check if currentWeapon is less than 3.

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