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

Hi, i have a problem to solve the step 95 of the first JavaScript algorithm
this is my current code and what ask me to do:
Change your if condition to check if currentWeapon is less than the length of the weapons array. An example of checking the length of an array myArray would look like myArray.length.

function buyWeapon() {
  if (currentWeapon < weapons.lenght) {
    if (gold >= 30) {
      gold -= 30;
      goldText.innerText = gold;
      let newWeapon = weapons[currentWeapon].name;
      text.innerText = "You now have a " + newWeapon + ".";
      text.innerText += " In your inventory you have: " + inventory;
    } else {
      text.innerText = "You do not have enough gold to buy a weapon.";

Thank you

1 Like

Welcome to the forum @pietombi

You have a typo in the condition statement.

It should be lengTH

Happy coding

1 Like

right code is