Role Playing Game - Step 85 (Help me with the logic)

Tell us what’s happening:

Nothing is happening. I’m actually going through this course again because I didn’t understand most of it. Some of the concepts weren’t defined or explained, like the upgrade() function having a paramater that closely matched the variable with an array of information related to the paramater’s name.

This one however I truly can’t understand. The instructions claim the variable currentWeapoon is linked to the const weapon array. HOW? How does the currentWeapon value of 0 indicate it is linked to the weapons array? Shouldn’t the code be: let currentWeapon = weapons [0]; instead?

I just need to understand the logic. Thanks in advance.

Your code so far

let currentWeapon = 0;


const weapons = [
{ name: ‘stick’, power: 5 },
{ name: ‘dagger’, power: 30 },
{ name: ‘claw hammer’, power: 50 },
{ name: ‘sword’, power: 100 }
];


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

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

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

Depending on the actual number currentWeapon is, it can indicate different weapons - weapons[currentWeapon]. currentWeapon doesn’t directly point to the weapon object, but using it as index with the weapons array allows obtaining the current weapon.

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