Learn Basic JavaScript by Building a Role PLaying Game - Step 97

can anybody help me with this question i am trying to work out if i put my statement in the right place

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!";
    }
  }
}```

You added your else statement to the inner if statement, you need to add it to outer if statement.

You need to add that else one time to the outer if as you have if nested inside, you can differ between them using its curly brackets { }, in your editor when you get your cursor next to it, it will highlight its related one automatically.

if (condition) {
    
  if (condition2) {



  } // here goes else for the inner if

} // here goes else for the outer if

I think you can solve it now.

1 Like

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