Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const numQuestions = document.querySelectorAll(".questionContainer").length;
- let correctAnswers = 0;
- document.getElementById("check").addEventListener("click", function(){
- correctAnswers = 0;
- for (let i = 1; i <=numQuestions;i++){
- document.querySelector("#question" + i).classList.remove("incorrect");
- document.querySelector("#question" + i).classList.remove("correct");
- }
- for (let i = 1; i <= numQuestions; i++){
- for (let j = 1; j <= 3; j++) {
- if (document.getElementById("q" + i + "-ans" + j).checked && document.getElementById("q" + i + "-ans" + j).classList.contains("correct")){
- correctAnswers++;
- document.querySelector("#question" + i).classList.remove("incorrect");
- document.querySelector("#question" + i).classList.add("correct");
- break;
- }
- else {
- document.querySelector("#question" + i).classList.add("incorrect");
- }
- }
- }
- document.getElementById("result").textContent = "Correct answers " + correctAnswers + "/" + numQuestions;
- })
Add Comment
Please, Sign In to add comment