-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquizz.js
71 lines (63 loc) · 2.13 KB
/
quizz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function infoBlocAnim() {
document.getElementById("infoBloc").style.opacity = "1";
document.querySelector("#underline").style.animation = "apparition-barre 1s";
setTimeout(() => {
document.querySelector("#underline").style.animation = "";
}, 1010);
}
let inputQuizz = document.querySelectorAll('#quizz input');
let oldElement= undefined; // Correspond à l'ancienne couche qui a été sélectionnée
function clearQuizz(oldElement) {
if(oldElement !== undefined) {
if (oldElement.style.fill === '#f1f1f1' || oldElement.style.fill === 'rgb(241, 241, 241)') {
oldElement.style.fill = "";
}else{
oldElement.style.stroke = "";
}
}
let oldAnswers = document.querySelectorAll('.correct-answer')
for(i = 0; i < oldAnswers.length; i++) {
oldAnswers[i].innerHTML = "";
}
for (i=0; i<inputQuizz.length;i++) {
inputQuizz[i].style.background = "#f1f1f1";
}
}
let answers = [];
function startQuizz(element) { // element correspond à l'ID de la couche
clearQuizz(oldElement);
oldElement = document.getElementById(element); // Redéfinie l'ancien élément avec l'actuel
infoBlocAnim();
answers = [];
if (data[element].couche) {
document.getElementById(element).style.fill = '#f1f1f1';
affichage('quizz-couche');
} else {
document.getElementById(element).style.stroke = '#f1f1f1';
affichage('quizz-discontinuite');
}
for (i in data[element]) {
if (i !== "densite" && i !== "couche") {
answers.push(data[element][i]);
}
}
}
function checkResponse() {
clearQuizz()
for (i = 0; i < answers.length; i++) {
if (inputQuizz[i].value === answers[i]) {
inputQuizz[i].style.background ="#64e964";
} else {
inputQuizz[i].style.background ="#d34b4b";
let correctAnswer = inputQuizz[i].nextElementSibling;
correctAnswer.innerHTML = answers[i]
}
}
}
window.addEventListener('keypress', (e) => {
if (quizzMode === true) {
if(e.key === "Enter") {
checkResponse()
}
}
})