@@ -176,6 +176,13 @@ function addEventListenerToNextButton() {
176
176
//Append every object of the table to the table table-results-body in the results.html page
177
177
function appendToTable ( qas ) {
178
178
179
+ var noteDisplay = document . getElementById ( "note-display" ) ;
180
+ var noteTitle = document . createElement ( "h1" ) ;
181
+
182
+ noteDisplay . appendChild ( noteTitle ) ;
183
+ noteDisplay . appendChild ( document . createElement ( "hr" ) ) ;
184
+
185
+
179
186
//Get the table body
180
187
var tableBody = document . getElementById ( "table-results-body" ) ;
181
188
var note = 0 ;
@@ -196,39 +203,59 @@ function appendToTable(qas) {
196
203
}
197
204
var userAnswer = qas [ i ] . getUserAnswer ( ) ;
198
205
206
+ var chckmrk = document . createElement ( "input" ) ;
207
+ chckmrk . setAttribute ( "type" , "checkbox" ) ;
208
+
209
+
210
+
199
211
//if the answer = userAnswer, the cell should be green and have a checkmark icon
200
212
//else the cell should be red and have a cross icon
201
213
if ( answer2 != undefined ) {
202
214
if ( userAnswer != undefined ) {
215
+
216
+
203
217
if ( answer . replace ( / \s + / g, '' ) == userAnswer . replace ( / \s + / g, '' ) || answer2 . replace ( / \s + / g, '' ) == userAnswer . replace ( / \s + / g, '' ) ) {
204
218
row . setAttribute ( "class" , "row-green" ) ;
205
- cell . innerHTML = "✔️" ;
219
+ chckmrk . checked = true ;
206
220
note ++ ;
207
221
} else {
208
222
row . setAttribute ( "class" , "row-red" ) ;
209
- cell . innerHTML = "❌" ;
223
+ chckmrk . checked = false ;
210
224
}
211
225
} else {
212
226
row . setAttribute ( "class" , "row-red" ) ;
213
- cell . innerHTML = "❌" ;
227
+ chckmrk . checked = false ;
214
228
}
215
229
} else {
216
230
if ( userAnswer != undefined ) {
217
231
if ( answer . replace ( / \s + / g, '' ) == userAnswer . replace ( / \s + / g, '' ) ) {
218
232
row . setAttribute ( "class" , "row-green" ) ;
219
- cell . innerHTML = "✔️" ;
233
+ chckmrk . checked = true ;
220
234
note ++ ;
221
235
} else {
222
236
row . setAttribute ( "class" , "row-red" ) ;
223
- cell . innerHTML = "❌" ;
237
+ chckmrk . checked = false ;
224
238
}
225
239
} else {
226
240
row . setAttribute ( "class" , "row-red" ) ;
227
- cell . innerHTML = "❌" ;
241
+ chckmrk . checked = false ;
228
242
}
229
243
230
244
}
231
245
246
+ chckmrk . addEventListener ( 'change' , function ( ) {
247
+ if ( this . checked ) {
248
+ console . log ( "Checkbox is checked.." ) ;
249
+ note ++ ;
250
+ testNote ( noteTitle , note , length ) ;
251
+ } else {
252
+ console . log ( "Checkbox is not checked.." ) ;
253
+ note -- ;
254
+ testNote ( noteTitle , note , length ) ;
255
+ }
256
+ } ) ;
257
+
258
+ cell . appendChild ( chckmrk ) ;
232
259
row . appendChild ( cell ) ;
233
260
// cell = document.createElement("td");
234
261
// //Set the text of the cell
@@ -273,8 +300,12 @@ function appendToTable(qas) {
273
300
//Append the row to the table body
274
301
tableBody . appendChild ( row ) ;
275
302
}
276
- var noteDisplay = document . getElementById ( "note-display" ) ;
277
- var noteTitle = document . createElement ( "h1" ) ;
303
+
304
+
305
+ testNote ( noteTitle , note , length ) ;
306
+ }
307
+
308
+ function testNote ( noteTitle , note , length ) {
278
309
noteTitle . innerHTML = note + "/" + length + " bonnes réponses (" + ( note / length * 100 ) . toFixed ( 2 ) + "%)" ;
279
310
//Change the title attribute of the noteTitle div
280
311
//Change the color of the title depending on the note
@@ -287,9 +318,4 @@ function appendToTable(qas) {
287
318
}
288
319
289
320
290
- noteDisplay . appendChild ( noteTitle ) ;
291
- noteTitle = document . createElement ( "hr" ) ;
292
- noteDisplay . appendChild ( noteTitle ) ;
293
-
294
-
295
321
}
0 commit comments