-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.js
More file actions
61 lines (47 loc) · 2.05 KB
/
Script.js
File metadata and controls
61 lines (47 loc) · 2.05 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
let currentQuestion = 0;
let correctanwers = 0
showQuestion();
function showQuestion() {
let pct = Math.floor((currentQuestion/questions.length)*100)
document.querySelector('.progress--bar').style.width = `${pct}%`
if (questions[currentQuestion]) {
let thequestion = questions[currentQuestion].question;
let questionarea = document.querySelector('.questionArea');
questionarea.style.display = 'block';
questionarea.querySelector('.question').innerHTML = thequestion;
let optionsHTML = '';
for (i in questions[currentQuestion].options) {
optionsHTML += `<div data-op='${i}' class='option'><span>${parseInt(i) + 1}</span> ${questions[currentQuestion].options[i]}</div>`;
}
document.querySelector('.options').innerHTML = optionsHTML;
document.querySelectorAll('.options .option').forEach(item => item.addEventListener('click', clickedOption));
}else { finished()}
}
function clickedOption(e) {
let clickedoption = parseInt(e.target.getAttribute('data-op'));
if(questions[currentQuestion].answer === clickedoption){
correctanwers++;
}
currentQuestion++
showQuestion()
}
function finished()
{ let text = " ";
if (correctanwers > 5) {
text = "Parabéns!!";
}
else
{text = "Precisa estudar mais...";}
document.querySelector('.scoreArea').style.display = 'block';
document.querySelector('.questionArea').style.display = 'none';
document.querySelector('.scoreText1').innerHTML = text;
document.querySelector('.scorePct').innerHTML = `Acertou ${(correctanwers /questions.length) *100}%`
document.querySelector('.scoreText2').innerHTML = `Você respondeu ${questions.length} e acertou ${correctanwers}`
document.querySelector('.scoreArea button').addEventListener('click', ()=>
{ currentQuestion = 0
showQuestion()
document.querySelector('.scoreArea').style.display = 'none';
document.querySelector('.progress--bar').style.width = `100%`
correctanwers = 0;
});
}