How Does This Function Work?

Below is the function I wrote for step 112 of “Learn Basic Javascript By Building a Role-playing Game”. My question is: if “fighting = 0;” is used to reference the “slime” object in my “monsters” array, how does the computer know to pull from the monsters array instead of another object array like “weapons” for example? Is it because function goFight will tell it which array to reference?

function fightSlime() {
  fighting = 0;
  goFight();
}

I know this is a noob question that will probably be answered by the other steps in the course but I just have to know.

Hi there!

You need to post your full JavaScript code for better assistant.

somewhere there is written monsters[fighting] and that will get the proper monster object

Welcome to the forum @jeff-upgraded

These functions will reference the fighting variable: goFight(), attack(), defeatMonster(), in the later parts of the project.

Happy coding

1 Like