File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 3636
3737< div class ="card ">
3838 < div class ="question " id ="question "> Loading...</ div >
39- < button onclick ="nextQuestion() "> Next</ button >
39+ < button id ="rightButton " style ="background-color: #4CAF50; color: white; margin-right: 1em; "> Right</ button >
40+ < button id ="wrongButton " style ="background-color: #f44336; color: white; "> Wrong</ button >
41+ < div id ="score " style ="font-size: 1.2em; margin-top: 1em; "> Score: 0</ div >
4042</ div >
4143
4244< script >
4345 fetch ( 'questions.json' )
4446 . then ( response => response . json ( ) )
4547 . then ( data => {
4648 const questions = data . questions ;
49+ let score = 0 ;
4750
4851 function nextQuestion ( ) {
4952 if ( questions . length > 0 ) {
5861 // Make it globally accessible to the button
5962 window . nextQuestion = nextQuestion ;
6063
64+ document . getElementById ( 'rightButton' ) . addEventListener ( 'click' , ( ) => {
65+ score ++ ;
66+ document . getElementById ( 'score' ) . innerText = `Score: ${ score } ` ;
67+ nextQuestion ( ) ;
68+ } ) ;
69+
70+ document . getElementById ( 'wrongButton' ) . addEventListener ( 'click' , ( ) => {
71+ nextQuestion ( ) ;
72+ } ) ;
73+
6174 // Load the first question
6275 nextQuestion ( ) ;
6376 } )
You can’t perform that action at this time.
0 commit comments