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

Tell us what’s happening:

I don’t understand what exactly I’m required to do in this step. I’ve tried everything but the code is still failing.

Your code so far

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

/* file: styles.css */

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

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
  if (currentWeapon <= 1 ) {
        currentWeapon -= 1;

// User Editable Region

Your browser information:

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

Challenge Information:

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

In this step, the lesson remeind aim of the currentWeapon variable as follows:

The value of the currentWeapon variable corresponds to an index in the weapons array. The player starts with a "stick", since currentWeapon starts at 0 and weapons[0] is the "stick" weapon.

If the player buys a new weapon, how can you display the current weapon? You should modify the index number of the weapons array to switch from the "stick" to a different weapon. Here’s how to do it:

In the buyWeapon function, use compound assignment to add 1 to currentWeapon - the user is buying the next weapon in the weapons array.

By modifying the currentWeapon variable value within the buyWeapon function, you will display a different weapon index from the weapons array. So you can achieve this with compound assignment (+=) to increase this value.

By the way you decrease to currentWeapon value in this code block, it should increase to show next weapon from weapons array.

Also you don’t need any currentWeapon value control in this step.

Happy coding :slightly_smiling_face:

It worked now
Thank you so much

You’re welcome, happy coding :slightly_smiling_face: