-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (45 loc) · 1.74 KB
/
app.js
File metadata and controls
54 lines (45 loc) · 1.74 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
function populate() {
if(quiz.isEnded()) {
showScores();
}
else{
// show question
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
//show choices
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]);
}
showProgress();
}
};
function guess(id, guess) {
var button = document.getElementById(id);
button.onclick = function() {
quiz.guess(guess);
populate();
}
}
function showProgress() {
var currentQuestionNumber = quiz.questionIndex + 1;
var element = document.getElementById("progress");
element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
}
function showScores() {
var gameoverHtml = "<h1>Result</h1>";
gameoverHtml += "<h2 id='score'> Your scores: " + quiz.score + "</h2>"
var element = document.getElementById("quiz");
element.innerHTML = gameoverHtml;
}
var questions = [
new Question("Which one is not an object oriented programming language?", ["Java", "C++", "C#", "C"], "C"),
new Question("Which language is used for styling web pages?", ["XML", "HTML", "CSS", "JQuery"], "CSS"),
new Question("There are ____ main components of objects oriented programming.", ["1", "6", "2", "4"], "4"),
new Question("Which language is used for web apps?", ["Javascript", "Python", "PHP", "All"], "All"),
new Question("MVC is a _______.", ["Language", "Library", "Framework", "All"] , "Framework")
];
var quiz = new Quiz(questions);
populate();