-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.js
More file actions
106 lines (95 loc) · 2.97 KB
/
code.js
File metadata and controls
106 lines (95 loc) · 2.97 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
var startQuiz = document.getElementById("startQuiz");
var begin = document.getElementById("begin");
var enterYourScore = document.getElementById("enterYourScore")
var submit = document.getElementById("submit");
var name = document.getElementById("yourName");
var pennedHighScores = document.getElementById("pennedHighScores");
//questions
var questionsBox = document.getElementById("questionsBox");
var titles = document.getElementById("titles");
var choiceA = document.getElementById("buttonA");
var choiceB = document.getElementById("buttonB");
var choiceC = document.getElementById("buttonC");
var choiceD = document.getElementById("buttonD");
var buttonEl = document.querySelector("#choice");
//Questiosn box invisble until start is pressed
questionsBox.style.display = "none";
enterYourScore.style.display = "none";
pennedHighScores.style.display = "none";
//click start button, then questions will appear and timer will start
startQuiz.addEventListener("click", function () {
begin.style.display = "none";
timeLeft();
promptQuestions();
});
i = 0;
function promptQuestions(event) {
if (i < questions.length) {
questionsBox.style.display = "block";
titles.textContent = questions[i].title;
choiceA.textContent = questions[i].choices[0];
choiceB.textContent = questions[i].choices[1];
choiceC.textContent = questions[i].choices[2];
choiceD.textContent = questions[i].choices[3];
}
else {
enterScore();
}
}
var timer = 75;
function nextQuestion (event) {
if (i < questions.length) {
i++;
// promptQuestions();
}
}
function timeLeft() {
var time = document.getElementById("timer");
var outOfTime = setInterval(function () {
timer--;
time.textContent = ("Time: " + timer);
if (timer === 0) {
clearInterval(outOfTime)
alert('Times up!! You should consider studying more.');
enterScore();
}
}, 1000)
}
questionsBox.addEventListener("click", function (event) {
var element = event.target;
if (element.matches("button") === true) {
var choice = element.textContent
console.log(choice);
// promptQuestions();
if (choice == questions[i].answer) {
alert("Great Job :)");
// promptQuestions();
nextQuestion();
}
else {
alert("Wrong Answer :(")
timer = timer - 10
// promptQuestions();
nextQuestion();
}
promptQuestions();
}
})
function enterScore() {
questionsBox.style.display = "none";
enterYourScore.style.display = "block";
document.getElementById("yourScore").value = timer;
}
function submitScore() {
localStorage.setItem("user", user);
var user = {
username: name,
highScore: timer,
};
console.log(user);
};
function highScoreBtn() {
begin.style.display = "none";
enterYourScore.style.display = "none";
pennedHighScores.style.display = "block";
}