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

Tell us what’s happening:

I dont know why the code below fails to update xpText and goldText?

function defeatMonster() {
goldText.innerText = Math.floor(monsters[fighting].level * 6.7);
xpText.innerText = monsters[fighting].level;
}
} I need guidance

Your code so far

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

/* file: styles.css */

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

function defeatMonster() {
 function defeatMonster() {
  goldText.innerText = Math.floor(monsters[fighting].level * 6.7);
  xpText.innerText = monsters[fighting].level;
}
}

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

Challenge Information:

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

you should not have the function definition twice

Adjusted, and the code still doesn’t pass.

what is your code now?

Keep the initial variables and assign them to the two elements below that code.

gold += Math.floor(monsters[fighting].level * 6.7);
xp += monsters[fighting].level;
// assign gold to goldText
// assign xp to xpText

You should have 4 lines of code inside the function, the two variables and then the use of them.

Thanks a lot but it still doesn’t pass

The code is below
gold += Math.floor(monsters[fighting].level * 6.7);
xp += monsters[fighting].level;
goldText.innerText = gold;
xpText.innerText = monsters[fighting].level;

xpText.innerText = monsters[fighting].level;

Use the xp variable instead, it already contains the value of monsters[fighting].level.

xp += monsters[fighting].level;

Got it now. Thank you so much

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