Skip to content
Advertisement

Can’t add an event listener to an element from an API

I am building a trivia webapp using an API and i want to add an event listener to the button with the correct answer so that when the user clicks it it will display a message saying they’re right and it’ll get a new question. Here’s how the code looks:

JavaScript

It tells me that the AddEventListener is not a function, how can I fix this?

Advertisement

Answer

Use a loop to fill in the answer elements. In that loop you can check if the current answer is the correct answer and add the event listener.

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