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

Tell us what’s happening:

I’m trying to increase the currentWeaponIndex by + 1 and I believe my code should be correct. I’ve tried the longer version using currentWeaponIndex = currentWeaponIndex + 1; and I also tried to increment the variable using currentWeaponIndex++ and neither works. I’ve tried resetting the step too.

I’ve tried chat gpt and it says it is correct too haha :smiley:

Your code so far

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

/* file: styles.css */

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

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

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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

The instruction says use compound assignment.

Look at how you do the same thing by using the short form operator

Thank you! You are a life saver!

I think the confusion for me was understanding the term compound assignment and seeing the difference here:
variable++
variable = variable + 1
variable += 1

I looked into it and I understand it bettter now, thank you!

I

2 Likes