Skip to content
Advertisement

Event Listener function not returning any value

I am lost and I would like to understand where is my error, or what should I check to figure it out.

I am building a simple Rock Scissors game. I can’t return any values from Event Listener function to a variable. Console.log returns undefined.

JavaScript

Thanks in advance. Also, if someone could tell me if my Event Listener is very bad, I would be grateful. “innerHTML” was the best way I could figure out.

If my coding is ridiculous, sorry for that – I have started few days ago!

Advertisement

Answer

An event listener is a function that gets executed when an event happens. In this case a click. You register what must happen when the click occurs. In this case you like to update the game state with the selected value.

A more standard way of setting data on a html element is using the data attribute. For example: <button data-choice="paper">Paper</button>.

HTML:

JavaScript

Js:

JavaScript

https://jsfiddle.net/h0z5vf7y/2/

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement