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

Tell us what’s happening:

The test is asking to check if the currentWeapon is less than weapons in the if statements. What is wrong with my code?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

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

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.169 Mobile/15E148 Safari/604.1

Challenge Information:

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

Does the currentWeapon have a length property?

1 Like

No it does not have a length property but the test requires to do the changes inside the if condition

Ohhh I figured it out
First I need to make the property .length and then I will able to deal with it thanks the test passed

You shouldn’t need to make anything have a property of length?

1 Like