This is a working JavaScript Practice Quiz made by a noob (me).
the problem? as you can see the quiz, you can keep on clicking the answer button after you picked your answer. How can I avoid this?? I try using **onclick = null ** but I couldn't set it back to click state.
Thank you for your answers!!!!! Here is the QUIZ
<script>
let answers = [{
question: "01 What year is it",
a: "1850",
b: "1920",
c: "*2020",
d: "1995",
correct: "c"
}, {
question: "02 What color is the Sun?",
a: "*Yellow",
b: "Red",
c: "Green",
d: "Purple",
correct: "a"
}, {
question: "03 How do you say 'Hello' in French?",
a: "I don't know",
b: "Hi?",
c: "Paris?",
d: "*Bonjour",
correct: "d"
}, {
question: "What was the color of Napoleon's white horse?",
a: "*White",
b: "Grey",
c: "DarkBlue",
d: "Rainbow",
correct: "a"
}];
var slideIndex = 0;
var scoring = 0;
var q = document.getElementById("questionheader");
var a = document.getElementById("a");
var b = document.getElementById("b");
var c = document.getElementById("c");
var d = document.getElementById("d");
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex = slideIndex + n);
}
function showSlides(n) {
a.classList.remove("green");
b.classList.remove("green");
c.classList.remove("green");
d.classList.remove("green");
a.classList.remove("red");
b.classList.remove("red");
c.classList.remove("red");
d.classList.remove("red");
a.classList.remove("borderGreen");
b.classList.remove("borderGreen");
c.classList.remove("borderGreen");
d.classList.remove("borderGreen");
document.getElementById("Goodjob").classList.remove("show")
if (n > 3) {
slideIndex = 3
}
if (n < 1) {
slideIndex = 0
}
q.innerHTML = answers[slideIndex].question;
a.innerHTML = answers[slideIndex].a;
b.innerHTML = answers[slideIndex].b;
c.innerHTML = answers[slideIndex].c;
d.innerHTML = answers[slideIndex].d;
}
function checkAnswers(choice) {
for (i = 0; i < answers.length; i++) {
let right = answers[i].correct
if (choice !== right && slideIndex == i) {
document.getElementById(choice).classList.add("red")
document.getElementById(right).classList.add("borderGreen")
} else if (choice === right && slideIndex == i) {
document.getElementById(right).classList.add("green")
document.getElementById("Goodjob").classList.add("show")
}
}
}
</script>