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

Tell us what’s happening:

i am asked to use compound assignment to add 1 to currentWeaponIndex. and i do not know if i am doing the right thing because it keeps rejecting my code.

Your code so far

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

/* file: styles.css */

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

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    currentWeaponIndex = 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/126.0.0.0 Safari/537.36

Challenge Information:

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

2 Likes

Hello,
It is almost correct just add + right before the = sign
Here is an example of compound Assignment:

a += 1;  // it is the same thing as a = a + 1

Read more about it :
Guide to Compound Assignment Operators in JavaScript (devcamp.com)

2 Likes

This sets the currentWeponIndex to equal 1

1 Like

Thank you! it worked

1 Like

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