-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
123 lines (112 loc) · 3.01 KB
/
Copy pathscript.js
File metadata and controls
123 lines (112 loc) · 3.01 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
var input1 = document.getElementById("buttonOne");
var input2 = document.getElementById("buttonTwo");
var input3 = document.getElementById("buttonThree");
var input4 = document.getElementById("buttonFour");
var start = document.getElementById("startButton");
var submit = document.getElementById("submitButton");
var displayEl = document.getElementById("display");
var i = 0;
var score = 0;
var selected = 0;
function populate() {
document.getElementById("currentQuestion").textContent = questions[i].q;
document.getElementById("buttonOne").textContent = questions[i].a[0];
document.getElementById("buttonTwo").textContent = questions[i].a[1];
document.getElementById("buttonThree").textContent = questions[i].a[2];
document.getElementById("buttonFour").textContent = questions[i].a[3];
}
start.addEventListener("click", function() {
i = 0;
score = 0;
var secondsLeft = 60;
var timerInterval = setInterval(function() {
secondsLeft--;
countDown.textContent = secondsLeft;
if (secondsLeft === 0) {
clearInterval(timerInterval);
alert("Time has run out. Game over");
return;
document.getElementById("startButton").style.visibility = "visible";
}
}, 1000);
populate();
input1.addEventListener("click", function() {
selected = 1;
});
input2.addEventListener("click", function() {
selected = 2;
});
input3.addEventListener("click", function() {
selected = 3;
});
input4.addEventListener("click", function() {
selected = 4;
});
submit.addEventListener("click", function() {
if (selected === questions[i].c) {
score++;
secondsLeft = secondsLeft + 3;
//displayEl.textContent = "Correct: " + score;
} else {
secondsLeft = secondsLeft - 3;
//displayEl.textContent = "Wrong: " + score;
}
i = i + 1;
if (i == 7) {
clearInterval(timerInterval);
var finalScore = secondsLeft * score;
var player = prompt(
"You have finished the quiz! Please enter your name to record your high score. " +
finalScore
);
}
populate();
});
});
var questions = [
{
q: "Who created Marvel Comics.",
a: ["Jim Lee", "Stan Lee", "Donald Trump", "Steve Jobs"],
c: 2
},
{
q: "Who is the leader of Shield?",
a: ["Captain America", "Nick Fury", "Tony Stark", "Black Widow"],
c: 2
},
{
q: "Where is Thor From?",
a: ["the moon", "Midgar", "Asgard", "Valhalla"],
c: 3
},
{
q: "What is Spider-man's real identity?",
a: ["Bruce Banner", "Bruce Wayne", "Steve Rogers", "Peter Parker"],
c: 4
},
{
q: "Who founded the X-men?",
a: ["Magneto", "Jean Grey", "Charles Xavier", "William Task"],
c: 3
},
{
q: "What planet is Super-man from?",
a: ["Klingon", "Krypton", "Jupiter", "Earth"],
c: 2
},
{
q: "What is Green Arrow's real name?",
a: [
"Wilson Fisk",
"Rupert Murdoch",
"Oliver Jonas Queen",
"Billie Jean King"
],
c: 3
},
{
q: " ",
a: [" ", " ", " ", " "],
c: 1
}
];