-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
125 lines (102 loc) · 3.66 KB
/
Copy pathscript.js
File metadata and controls
125 lines (102 loc) · 3.66 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const progression = document.getElementById("progression");
const question = document.getElementById("question");
const barreProgression = document.getElementById("barreProgression");
const listeChoix = document.getElementById("listeChoix");
const btnSuivant = document.getElementById("btnSuivant");
const resultatScore = document.getElementById("resultatScore");
const resultatMessage = document.getElementById("resultatMessage");
const btnRecommencer = document.getElementById("btnRecommencer");
const quiz = document.getElementById("quiz");
const ecranTerminal = document.getElementById("ecranTerminal");
const questions = [
{
question: "Quelle est la capitale de la Côte d'Ivoire ?",
choix: ["Abidjan", "Yamoussoukro", "Bouaké", "Yopougon"],
bonneReponse: 1
},
{
question: "Combien font 7 × 8 ?",
choix: ["54", "56", "40", "64"],
bonneReponse: 1
},
{
question: "Quel langage est utilisé pour styliser une page web ?",
choix: ["HTML", "CSS", "JavaScript", "Python"],
bonneReponse: 1
},
{
question: "Combien de continents y a-t-il sur Terre ?",
choix: ["5", "6", "7", "8"],
bonneReponse: 2
}
];
let indiceActuel = 0;
let score = 0;
let reponseSelectionnee = null;
function afficherQuestion() {
reponseSelectionnee = null;
btnSuivant.disabled = true;
const questionActuelle = questions[indiceActuel];
progression.textContent = `Question ${indiceActuel + 1} / ${questions.length}`;
const pourcentage = (indiceActuel / questions.length) * 100;
barreProgression.style.width = `${pourcentage}%`;
question.textContent = questionActuelle.question;
listeChoix.innerHTML = "";
questionActuelle.choix.forEach((choix, index) => {
const bouton = document.createElement("button");
bouton.className = "btn-choix";
bouton.textContent = choix;
bouton.addEventListener("click", () => selectionnerReponse(index));
listeChoix.appendChild(bouton);
});
}
function selectionnerReponse(indexChoix) {
if (reponseSelectionnee !== null) return;
reponseSelectionnee = indexChoix;
const questionActuelle = questions[indiceActuel];
const boutonsChoix = document.querySelectorAll(".btn-choix");
boutonsChoix.forEach((bouton, index) => {
bouton.disabled = true;
if (index === questionActuelle.bonneReponse) {
bouton.classList.add("correct");
} else if (index === indexChoix) {
bouton.classList.add("incorrect");
}
});
if (indexChoix === questionActuelle.bonneReponse) {
score++;
}
btnSuivant.disabled = false;
}
function questionSuivante() {
indiceActuel++;
if (indiceActuel < questions.length) {
afficherQuestion();
} else {
afficherResultat();
}
}
function afficherResultat() {
barreProgression.style.width = "100%";
quiz.classList.add("cache");
ecranTerminal.classList.remove("cache");
resultatScore.textContent = `${score} / ${questions.length}`;
const pourcentageReussi = (score / questions.length) * 100;
if (pourcentageReussi === 100) {
resultatMessage.textContent = "Score parfait, bravo !";
} else if (pourcentageReussi >= 60) {
resultatMessage.textContent = "Bien joué !";
} else {
resultatMessage.textContent = "Peut faire mieux !";
}
}
function recommencerQuiz() {
indiceActuel = 0;
score = 0;
ecranTerminal.classList.add("cache");
quiz.classList.remove("cache");
afficherQuestion();
}
btnSuivant.addEventListener("click", questionSuivante);
btnRecommencer.addEventListener("click", recommencerQuiz);
afficherQuestion();