Maybe my brain has melted a little bit and I’m not thinking straight/or this is a stupid question, but I don’t get it. Can someone explain, in very “tell me like I’m 5” explanations why this is done? For some reason this is the only part of this lesson that is confusing me.
The first step to answering this question is to understand what each of those variables represent, in other words, what values they hold. So what does the variable
monsters hold? What does the variable
I think const monsters holds the objects of the name, level, and health of each of the monsters. As for fighting, other than being declared at the top of let = fighting, I see that it is also used in the functions for fightSlime, fightBeast, fightDragon, with 0 , 1, and 2.(At the point of step 116) Am I on the right track?
Yes, monsters holds the individual monster objects. But I think we need to be a little more specific. It is an “array” of monster objects. So how do you access an item in an array? Based on that, what do you think the variable
fighting will be? And not just its literal value. What is that variable being used to track? It’s name should give it away
You access it with , I believe, so is fighting supposed to represent the monster you are fighting? By the number it uses? Is that the logic to it?
Yes, you use brackets to access an element in an array, but what goes inside of those brackets? There are three possible monsters to fight. What do you think the variable
fighting is used for?
Ahh, sorry, I just realized that you answered this question in your previous post, I just didn’t read it as well as I should have.
fighting keeps track of the monster you are currently fighting.
So now that you know what
fighting represent, what does
monsters[fighting] get you?