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

Tell us what’s happening:

This is the output i get.

Your buyHealth function should update the text of healthText to be the value of health .

Your code so far


function buyHealth() {
  gold -= 10;
  health += 10;
  const healthText = document.querySelector('#healthText');
  healthText.innerText = health;
  const goldText = document.querySelector("goldText");
  goldText.innerText = gold;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36

Challenge Information:

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

Hello!

Suggestion:

No need to declare the goldText and healthText again. They were declared at the beginning.
Remove these lines of code.

Leave the healthText.innerText code and the goldText.innerText code with the assigned values of health and gold.

Happy coding.

1 Like

Thank you.
simpler than i thought

2 Likes

You are welcome.

I think we all tend to make it a bit more difficult.

Happy coding!

2 Likes

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