the buttons when clicked are represented by the functionsbuyHealth , buyWeapon , and goTown and this code is still written within the function goStore()
Ok, so in that exercise itself, you actually don’t even have to define these functions. The tests that run do not check for this. You mentioned:
In Step 45:
the buttons when clicked are represented by the functionsbuyHealth , buyWeapon , and goTown and this code is still written within the function goStore()
why?
You are simply assigning the buttons these functions that you will actually implement as you move to Step 47. You are assigning a different behavior to these buttons when the goStore button is clicked. That way you can make sure that buyHealth, buyWeapon, and goTown functions only run when the goStore button is already clicked once and the buttons display “Buy 10 health (10 gold)”, “Buy weapon (30 gold)”, and “Go to town square”. I hope this answers your question. If not, please let me know and I will try my best to clarify further.
why this answer isn’t accepted
function goStore() {
button1.innerText = “Buy 10 health (10 gold)”;
button2.innerText = “Buy weapon (30 gold)”;
button3.innerText = “Go to town square”;
button1.onclik = buyHealth;
button2.onclik = buyWeapon;
button3.onclik = goTown;
};
it keeps saying you have to update button1 to buyHealth
We do not allow people to post solution code but in this case, as it isn’t correct I will leave it.
The test needs to be updated so your code will correctly fail the test (PR is in progress).
You should not call () the handler functions. Doing so will break the handler.
It should be
someBtn.onclick = someFn;
and not
someBtn.onclick = someFn();
The first assigns the function so it can be called by the onclick event, the second assigns the return value of calling the function, which is not the function, so the onclick event will not have a function to call.