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

Tell us what’s happening:

Hi I am just learning javascript so don’t know exactly what i am doing f
so thanks for all your help

function buyWeapon() {currentWeaponIndex += 1
  if (gold >= 30) {
    gold -= 30;
    
  }
}

what am i doing wrong. thanks.

Your code so far

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

/* file: styles.css */

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

function buyWeapon() {currentWeaponIndex += 1
  if (gold >= 30) {
    gold -= 30;
    
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge Information:

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

here when the gold is subtracted you should increase currentWeaponIndex to give the player the new just purchased weapon

I’ve edited your post for readability. Next time please don’t use backticks in this form to describe your issue. Thanks.

1 Like

function buyWeapon() {currentWeaponIndex += 1
if (gold >= 30) {
gold -= 30;
currentWeaponIndex += 1;

}
}
is this whaat you mean thanks

yes, but you are increasing the index twice, it should be only once

it still doesn’t pass but thanks everyone for all your help

function buyWeapon() {
if (gold >= 30) {
gold -= 30;
currentWeaponIndex += 1;
}
}

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

i am using a google chromebook on these webpages so don’t `have a f5 key

thanks anyway still not passing i will eventually solve it.