Hey!
The clickOnKeyPress
function adds an event listener to the theme toggle every time the function is called. Since the function is called every time a question is set up, the toggle will have multiple event listeners, and so one click will toggle the theme multiple times!
I'd use a <button>
element for this toggle, but another solution would be to create a unique setup function for the theme toggle. It shouldn't need the || event.key === " "
part of the function since the browser handles space presses by default.
Marked as helpful
@catreedle
Posted
thank you. your insight is very much appreciated :) @markuslewin