-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquizzz.js
57 lines (43 loc) · 1.68 KB
/
quizzz.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
function move() {
if(quiz.isEnded()) {
showScore();
}
else {
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
var choices = quiz.getQuestionIndex().choices;
for(var i = 0; i < choices.length; i++) {
var element = document.getElementById("choice" + i);
element.innerHTML = choices[i];
guess("btn" + i, choices[i]);
}
Progress();
}
};
function guess(id, guess) {
var button = document.getElementById(id);
button.onclick = function() {
quiz.guess(guess);
move();
}
};
function Progress() {
var currentQuestionNumber = quiz.questionIndex + 1;
var element = document.getElementById("progress");
element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
};
function showScore() {
var gameOverHTML = "<h1>Result</h1>";
gameOverHTML += "<h2 id='score'> Your score: " + quiz.score + "</h2>";
var element = document.getElementById("quiz");
element.innerHTML = gameOverHTML;
};
var questions = [
new Question("Which one is not a front-end language", ["HTML", "CSS","JS", "PHP"], "PHP"),
new Question("Which language is used for styling web pages?", ["HTML", "JS", "CSS", "PHP"], "CSS"),
new Question("Which of the following are markup languages.", ["HTML", "XHTML","XML", "All"], "All"),
new Question("Which language is a scripting language?", ["PHP", "Python", "JS", "All"], "All"),
new Question("Javascript is a ____.", ["Programming Language", "Library", "Framework", "All"], "Programming Language")
];
var quiz = new Quiz(questions);
move();