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

Tell us what’s happening:

Not really sure what is going wrong with this code here

Your code so far

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

/* file: styles.css */

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

function fightSlime() {
    fighting = location[monsters][0];
    update.gofight();
}

// 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/131.0.0.0 Safari/537.36

Challenge Information:

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

In your fightSlime function, set fighting equal to 0 - the index of slime in the monsters array. Remember that you already declared fighting earlier in your code, so you do not need let or const here.

On the next line, call the goFight function.

Explicitly set fighting equal to 0. Simple as that.
Then, just call the goFight function. Note that it is goFight not gofight.

But in the other exercise it was location[item][num];

I don’t know which exercise you’re referring to but location[monsters][0] is meaningless. You have a monsters array and index 0 is an object:

{
    name: "slime",
    level: 2,
    health: 15
  }

However, location is not a valid javascript keyword.
The reason this is mentioned in the instructions, is that fighting is assigned a numerical value, equivalent to an array index so, for instance, monsters[fighting] is a reference to the above object, when the value of fighting is 0.

It was talked about in the arguments part…

some of the properties of the objects in locations are arrays, there it makes sense to write locations[..][..].