|
| 1 | + |
| 2 | +const quizBox = [ |
| 3 | + { question :"Q1 : What is the Full Form Of HTML ? ", |
| 4 | + a :"Hello To My Land ", |
| 5 | + b :"Hey Markup Text Language", |
| 6 | + c :"Hyper Markup Language", |
| 7 | + d :"HyperText Markup Language", |
| 8 | + ans : "ans4" , |
| 9 | + |
| 10 | + }, |
| 11 | + { question :"Q2 : What is the Full Form Of JS ? ", |
| 12 | + a :"JavaScript ", |
| 13 | + b :"Java Scope", |
| 14 | + c : "Jango scoping", |
| 15 | + d : " JavaStyle", |
| 16 | + ans : "ans1" , |
| 17 | + }, |
| 18 | + { question :"Q3 : What is the Full Form Of CSS ? ", |
| 19 | + a :"Cascading Style Sheep", |
| 20 | + b :"Cascading Style Sheet", |
| 21 | + c : "Cartoons Style Sheets", |
| 22 | + d : "Cascading Super Sheet", |
| 23 | + ans : "ans2" , |
| 24 | + }, |
| 25 | + { question :"Q4 : What is the Full Form Of HTML ? ", |
| 26 | + a :"Hello To My Land ", |
| 27 | + b :"Hey Markup Text Language", |
| 28 | + c : "HyperText Markup Language", |
| 29 | + d : "Hyper Markup Language", |
| 30 | + ans : "ans3" , |
| 31 | + }, |
| 32 | +] |
| 33 | +const questions = document.querySelector(".head"); |
| 34 | +const option1 = document.querySelector("#option1"); |
| 35 | +const option2 = document.querySelector("#option2"); |
| 36 | +const option3 = document.querySelector("#option3"); |
| 37 | +const option4 = document.querySelector("#option4"); |
| 38 | +const btn = document.querySelector("#submit"); |
| 39 | +const answers = document.querySelectorAll(".answer"); |
| 40 | +const showScore = document.querySelector("#showScore"); |
| 41 | + |
| 42 | +let questionCount = 0 ; |
| 43 | +let score = 0 ; |
| 44 | + |
| 45 | +function loadQuestion(){ |
| 46 | + const questionList = quizBox[questionCount] ; |
| 47 | + questions.innerText = questionList.question ; |
| 48 | + option1.innerHTML = questionList.a ; |
| 49 | + option2.innerHTML = questionList.b ; |
| 50 | + option3.innerHTML = questionList.c ; |
| 51 | + option4.innerHTML = questionList.d ; |
| 52 | + |
| 53 | +} |
| 54 | +loadQuestion(); |
| 55 | + |
| 56 | +function getAnswer(){ |
| 57 | + let answer ; |
| 58 | + answers.forEach((curAnsEl ) => { |
| 59 | + if(curAnsEl.checked){ |
| 60 | + answer = curAnsEl.id; |
| 61 | + } |
| 62 | + }); |
| 63 | + return answer; |
| 64 | +} |
| 65 | + |
| 66 | +btn.addEventListener('click' , ()=>{ |
| 67 | + const checkedAnswer = getAnswer(); |
| 68 | + |
| 69 | + if( checkedAnswer === quizBox[questionCount].ans){ |
| 70 | + score++ ; |
| 71 | + } |
| 72 | + |
| 73 | + questionCount ++ ; |
| 74 | + |
| 75 | + if(questionCount < quizBox.length){ |
| 76 | + loadQuestion(); |
| 77 | + } |
| 78 | + else{ |
| 79 | + showScore.innerHTML = |
| 80 | + ` <h3> Your Score ${score} / ${ quizBox.length} </h3> |
| 81 | + <button id="btn1" onclick="location.reload()" >Play Again </button>`; |
| 82 | + showScore.style.display = "block" ; |
| 83 | + |
| 84 | + } |
| 85 | +}) |
0 commit comments