Im really stuck on this. Codepen included

So if you try and play the quiz, im attemping to make you can get through the first question and the second question will pop up but it wont go past that no matter what.

If you look at my function checkForCorrectAnswer() at the bottom of the JS, im increasing the arrayIndex when you get a correct answer to move to the next question. It does this and works well for the first question and it does indeed increase the arrayIndex, however, if you try to answer the second question it will no longer increase.

I have been stumped on this for quite some time and i cant figure out what is wrong with my code.

You need to add the even listener at the end of your renderQuestions function. Every time you change the innerHTML of the element, you’re replacing the original contents, so the action listener that you applied at first isn’t attached to the new element. You could add a line like this:

document.getElementsByClassName(‘question-submit-button’)[0].addEventListener(‘click’, checkForCorrectAnswer)

You rock! I will try it out when i get home later. Thank you!

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