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

Tell us what’s happening:

Dear Friends, i do not understand how the value of fighting in slime and other monster being fought represent the index of the in monsters arrays, why should it not be
fighting = monsters[0]; to indicate the index in array instead of
fighting = 0;
Why are we not using bracket notation.
I have passed this level but i have fail to understand something about the index number.
I will really appreciate Your explanation . Thank you.

Your code so far

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

/* file: styles.css */

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

function fightSlime() {
  fighting = 0;

}

// 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 112

Hi @Domondi

The global fighting variable is used to set the index number.

This code will access the first object in the monsters array.

This code assigns 0 to the fighting variable.

In later steps you will use the fighting variable to select the monsters array. This way, changing this single variable will access the various array elements.

Happy coding

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