ARTICLE AD BOX
I'm trying to make a quiz in JavaScript and have my questions in an object and now need to display them in a paragraph. After a certain amount of time, it goes onto the next question in the list.
But, for some reason, it's all just blank text when I try it out. I haven't worked with objects in JS before so I'm not sure what I am doing wrong.
Everything else should be good, it's working fine so far and the paragraph properly displays text if I just put a normal string.
const questions = [ { q1: "question1", ra1: "right answer 1", wa1: "wrong answer 1" }, { q2: "question2", ra2: "right answer 2", wa2: "wrong answer 2" }, { q3: "question3", ra3: "right answer 3", wa3: "wrong answer 3" } ] var start = document.getElementById("start") var question = document.getElementById("question") var o1 = document.getElementById("o1") var o2 = document.getElementById("o2") var i = 0 var clicked = false o1.addEventListener("click", checkclicked) o2.addEventListener("click", checkclicked) function checkclicked(){ clicked = true } start.addEventListener("click", startTimer) function startTimer(){ startInterval = setTimeout(startTimer, 6000) start.disabled = true o1.hidden = false o2.hidden = false switch(i){ case 0: question.textContent = questions.q1 break case 1: question.textContent = questions.q2 break case 2: question.textContent = questions.q3 break } i++ if(clicked == true){ clearTimeout(startInterval) clicked = false return } if(i > 6){ clearTimeout(startInterval) start.disabled = false o1.hidden = true o2.hidden = true i = 0 clicked = false return } }