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

I don’t understand what I am suppose to do here. I need help

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

Challenge Information:

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

First, you changed something that you shouldn’t have. The original code inside the function was:

gold -= 10;
health += 10;

You changed the second line.

Second, you don’t need to use querySelector to get the elements, you have already done that. Look at lines 14 and 15 of your code:

const healthText = document.querySelector("#healthText");
const goldText = document.querySelector("#goldText");

You want to set the innerText on these existing variables.

I can definitely see why you added the querySelectors though. The example in the instructions sort of implies that you should do that. The example is just trying to be completely correct, so it had to add the querySelector since the variable total didn’t already exist. But in your case, the variables goldText and healthText already exist, so you don’t need to declare them again.

The note at the very end of the instructions:

" Note: Your answer should only be two lines of code."

This means that you should only add two new lines of code to get the right answer.

3 Likes

Thank you so much.
It is solved.

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