1+ const quizDB = [
2+ {
3+ question : "1.Which one of the following river flows between Vindhyan and Satpura ranges?" ,
4+ a : "Narmada" ,
5+ b : "mahanadi" ,
6+ c : "son" ,
7+ d : "netravati" ,
8+ ans : "ans1" ,
9+ } ,
10+ {
11+ question : "2.The Central Rice Research Station is situated in?" ,
12+ a : "chennai" ,
13+ b : "cuttack" ,
14+ c : "banglore" ,
15+ d : "quilon" ,
16+ ans : "ans2" ,
17+ } ,
18+ {
19+ question : "3.Who among the following wrote Sanskrit grammar?" ,
20+ a : "kalidasa" ,
21+ b : "charak" ,
22+ c : "panini" ,
23+ d : "aryabhatt" ,
24+ ans : "ans3" ,
25+ } ,
26+ {
27+ question : "4. Which among the following headstreams meets the Ganges in last?" ,
28+ a : "Alaknanda" ,
29+ b : "Pindar" ,
30+ c : "Mandakini" ,
31+ d : "Bhagirathi" ,
32+ ans : "ans4" ,
33+ } ,
34+ {
35+ question : "5. Which among the following headstreams meets the Ganges in last?" ,
36+ a : "Yoga sutra" ,
37+ b : "panchatantra" ,
38+ c : "brahmasutra" ,
39+ d : "ayurveda" ,
40+ ans : "ans1" ,
41+ } ,
42+ ] ;
43+
44+ const question = document . querySelector ( ".question" ) ;
45+ const option1 = document . querySelector ( "#option1" ) ;
46+ const option2 = document . querySelector ( "#option2" ) ;
47+ const option3 = document . querySelector ( "#option3" ) ;
48+ const option4 = document . querySelector ( "#option4" ) ;
49+ const submit = document . querySelector ( "#submit" ) ;
50+ const answers = document . querySelectorAll ( ".answer" ) ;
51+ const showScore = document . querySelector ( "#showScore" ) ;
52+ let questionCount = 0 ;
53+ let score = 0 ;
54+
55+ const loadQuestion = ( ) => {
56+ const questionList = quizDB [ questionCount ] ;
57+ question . innerText = questionList . question ;
58+ option1 . innerText = questionList . a ;
59+ option2 . innerText = questionList . b ;
60+ option3 . innerText = questionList . c ;
61+ option4 . innerText = questionList . d ;
62+ } ;
63+
64+ loadQuestion ( ) ;
65+
66+ const getcheckedAnswer = ( ) => {
67+ let answer ;
68+ answers . forEach ( ( current ) => {
69+ if ( current . checked ) {
70+ answer = current . id ;
71+ }
72+ } ) ;
73+ return answer ;
74+ } ;
75+
76+ const deselectAll = ( ) => {
77+ answers . forEach ( ( current ) => ( current . checked = false ) ) ;
78+ } ;
79+
80+ submit . addEventListener ( "click" , ( ) => {
81+ const checkedAnswer = getcheckedAnswer ( ) ;
82+ console . log ( checkedAnswer ) ;
83+ if ( checkedAnswer == quizDB [ questionCount ] . ans ) {
84+ score ++ ;
85+ }
86+ questionCount ++ ;
87+ deselectAll ( ) ;
88+ if ( questionCount < quizDB . length ) {
89+ loadQuestion ( ) ;
90+ } else {
91+ showScore . innerHTML = `
92+ <h3> You Scored ${ score } /${ quizDB . length } </h3>
93+ <button class="btn" onclick="location.reload()">Play Again</button>
94+ ` ;
95+ showScore . classList . remove ( "scoreArea" ) ;
96+ }
97+ } ) ;
0 commit comments