Stuck on step 40 Learn Basic JavaScript by Building a Role Playing Game

Step 40

button1 represents your first button element. These elements have a special property called onclick, which you can use to determine what happens when someone clicks that button.

You can access properties in JavaScript a couple of different ways. The first is with dot notation. Accessing the onclick property of a button would look like:


Use dot notation to set the onclick property of your button1 to the function reference of goStore. Note that button1 is already declared, so you don’t need to use let or const.

Hi @dyavalo !

Welcome to the forum!

Can you show us with you have tried so far so we can best assist you?

Also, when posting to the forum, it is best to include the challenge link. I have updated your post to include that.

1 Like

i did not actually understand, what does it want, cuz i was doing this long ago and then after 2-3 month im back and i forgot what is assigning and all that.

Ty for reply

you need to assign the function goStore to the onclick property, so to have the function execute when the button is clicked

can you please show me example i did not understand, ty

assigning is done with the = operator, so you need to put the function goStore to the right of the assignment operator, when you have on the left button1.onclick

The onclick event attribute is used on buttons to execute some javascript when the button is clicked.

Here is another example for better understanding.

Every time you click on the button, a message appears in the container. That addMessageToContainer function will fire each time the button is clicked.

That is what this code is doing

displayBtn.onclick = addMessageToContainer;

You need to do something similar for this RPG challenge

You can see the full code in that codepen so you can better understand how all of the pieces work together.

Hope that helps

1 Like

you just need to add onclick button under button.innerText

and it will be like this:

buttonA.onclick = A
buttonB.onclick = B