-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (51 loc) · 2.73 KB
/
app.js
File metadata and controls
78 lines (51 loc) · 2.73 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
function populate() {
if(quiz.isEnded()) {
showScores();
}
else {
// show question
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
// show options
var choices = quiz.getQuestionIndex().choices;
for(var i = 0; i < choices.length; i++) {
var element = document.getElementById("choice" + i);
element.innerHTML = choices[i];
guess("bt" + 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;
};
// create questions
var questions = [
new Question("1. What is the Commercial Capital of India?", ["A. New Delhi", "B. Mumbai","C. Jaipur", "D. Kolkata"], "B. Mumbai"),
new Question("2. The line which divides the earth in to two equal parts?", ["A. Tropic of cancer", "B. Tropic of capricon","C. Equater", "D. Lattitude"], "C. Equater"),
new Question("3. National River of India?", ["A. Yamuna", "B. Ganga","C. Brahmputra", "D. Sindhu"], "B. Ganga"),
new Question("4. Currency of India?", ["A. Dollar", "B. Rupee","C. Euro", "D. Pound"], "B. Rupee"),
new Question("5. Which of the following contury does not share its border with india?", ["A. Nepal", "B. Bhutan","C. Kazakhastan", "D. Afganistan"], "C. Kazakhastan"),
new Question("6. Which of the following is Prime number?", ["A. 59", "B. 729","C. 6", "D. 8"], "A. 59"),
new Question("7. Which acid is present in humen digestive system?", ["A. Acetic acid", "B. Sulphuric acid","C. Nitric acid", "D. Hydro cloric acid"], "D. Hydro cloric acid"),
new Question("8. Pigment present in a plant responsible for its green colour?", ["A. Chloroplast", "B. Haemoglobin","C. Photosynthesis", "D. Cellulose"], "A. Chloroplast"),
new Question("9. Hardest substance?", ["A. Iron", "B. Tungestion","C. Diamond", "D. Gold"], "C. Diamond"),
new Question("10. Smallest bone in human body?", ["A. Backbone", "B. Diaphram","C. Stapes", "D. Ligament"], "C. Stapes"),
];
var quiz = new Quiz(questions);
populate();