@@ -84,6 +84,23 @@ function showQuestion(){
84
84
}
85
85
} ;
86
86
87
+ for ( let i = 0 ; i < questions [ 0 ] . content . length ; i ++ ) {
88
+ var currentQuestion = document . getElementById ( i ) ;
89
+ console . log ( currentQuestion ) ;
90
+ if ( i == currentQuestionIndex ) {
91
+ currentQuestion . style . width = "35px" ;
92
+ currentQuestion . style . height = "35px" ;
93
+ currentQuestion . style . borderRadius = "15px" ;
94
+ currentQuestion . style . background = "#5b52bf" ;
95
+ currentQuestion . style . color = "#FFF" ;
96
+ currentQuestion . style . fontWeight = "bold" ;
97
+ } else {
98
+ currentQuestion . style . width = "30px" ;
99
+ currentQuestion . style . height = "30px" ;
100
+ currentQuestion . style . borderRadius = "12px" ;
101
+ }
102
+ }
103
+
87
104
renderMathInElement ( document . body ) ;
88
105
if ( answer . correct ) {
89
106
button . dataset . correct = answer . correct ;
@@ -111,33 +128,18 @@ function showIndex(){
111
128
var number = i ;
112
129
index . setAttribute ( 'id' , number ) ;
113
130
114
- indexButton . addEventListener ( "click" , goToIdex ) ;
115
-
116
131
117
132
let currentQuestion = questions [ 0 ] . content [ currentQuestionIndex ] ;
118
133
//console.log(currentQuestion + " " + currentQuestionIndex );
119
134
indexButton . appendChild ( index ) ;
120
135
}
121
136
}
122
137
123
- function colorIndex ( ) {
124
- for ( let i = 0 ; i <= questions [ 0 ] . content . length ; i ++ ) {
125
- var index = document . getElementById ( '0' ) ;
126
- //console.log(index.id);
127
- if ( tableVerite [ i ] = - 1 ) { index . style . backgroundColor = "#7e74e2" ; }
128
- //else{index.style.backgroundColor = "#FAF";}
129
- //data-answer-btn = "btn-" + i;
130
- }
131
- //console.log(tableVerite);
132
-
133
- }
134
-
135
- function goToIdex ( event ) {
136
- const clickedButton = event . target
137
- //console.log(clickedButton);
138
- var questionDemandee = parseInt ( clickedButton . dataset . index , 10 ) ;
139
- currentQuestionIndex = questionDemandee - 1
140
- showQuestion ( ) ;
138
+ function colorIndex ( index ) {
139
+ var button = document . getElementById ( index ) ;
140
+ if ( tableVerite [ index ] == - 1 ) { button . style . backgroundColor = "#7e74e2" ; }
141
+ if ( tableVerite [ index ] == 0 ) { button . style . backgroundColor = "#ea9a9a" ; }
142
+ if ( tableVerite [ index ] == 1 ) { button . style . backgroundColor = "#9AEABC" ; }
141
143
}
142
144
143
145
@@ -164,13 +166,16 @@ function selectAnswer(e){
164
166
const isCorrect = selectedBtn . dataset . correct === "true" ;
165
167
if ( isCorrect ) {
166
168
selectedBtn . classList . add ( "correct" ) ;
167
- tableVerite [ currentQuestionIndex ] = 1 ;
168
- console . log ( tableVerite ) ;
169
+ tableVerite [ currentQuestionIndex ] = 1 ;
170
+ console . log ( "correct " + tableVerite )
169
171
score ++ ;
170
172
} else {
171
173
selectedBtn . classList . add ( "incorrect" ) ;
172
- tableVerite [ currentQuestionIndex ] = 0 ;
174
+ tableVerite [ currentQuestionIndex ] = 0 ;
175
+ console . log ( "incorrect " + tableVerite )
173
176
}
177
+ console . log ( "colorindex " + tableVerite )
178
+ colorIndex ( currentQuestionIndex ) ;
174
179
Array . from ( answerButtons . children ) . forEach ( button => {
175
180
if ( button . dataset . correct === "true" ) {
176
181
button . classList . add ( "correct" ) ;
@@ -198,7 +203,6 @@ function handleNextButton(){
198
203
currentQuestionIndex ++ ;
199
204
if ( currentQuestionIndex < questions [ 0 ] . content . length ) {
200
205
showQuestion ( ) ;
201
- colorIndex ( )
202
206
} else {
203
207
showScore ( ) ;
204
208
}
@@ -209,6 +213,11 @@ nextButton.addEventListener("click", ()=>{
209
213
if ( currentQuestionIndex < questions [ 0 ] . content . length ) {
210
214
handleNextButton ( ) ;
211
215
} else {
216
+ for ( let i = 0 ; i < questions [ 0 ] . content . length ; i ++ ) {
217
+ var button = document . getElementById ( i ) ;
218
+ button . style . backgroundColor = "#7e74e2" ;
219
+ }
220
+
212
221
startQuizz ( ) ;
213
222
}
214
223
} ) ;
0 commit comments