1
1
2
2
var beginButton = document . querySelector ( "#beginButton" ) ;
3
3
var startPage = document . querySelector ( "#startPage" ) ;
4
+ var scoresLink = document . querySelector ( "#scoresLink" ) ;
5
+
6
+ var question3 = document . createElement ( "h2" )
7
+
8
+ var totalCorrect = 0 ;
9
+ var timeLeft = 31 ;
4
10
5
11
Quiz ( ) ;
6
12
7
13
function Quiz ( ) {
14
+ scoresLink . setAttribute ( "style" , "display:none" ) ;
15
+
8
16
beginButton . addEventListener ( "click" , function ( ) {
9
17
startPage . style . display = "none" ;
10
18
runQuiz ( ) ;
11
-
12
19
} )
13
20
21
+ function loadScoreScreen ( ) {
22
+ // stops the clock and hides it
23
+ timeRemains = false ;
24
+ countdown . setAttribute ( "style" , "display:none" ) ;
25
+ // hides the second question screen
26
+ question3 . setAttribute ( "style" , "display:none" ) ;
27
+
28
+ var finalScorePageHeader = document . createElement ( "h2" ) ;
29
+ var finalScoreGreeting = document . createElement ( "p" ) ;
30
+ var finalScoreEntry = document . createElement ( "input" ) ;
31
+ var finalScoreButton = document . createElement ( "button" ) ;
32
+
33
+ calculateFinalScore ( ) ;
34
+
35
+ function calculateFinalScore ( ) {
36
+ finalScore = totalCorrect + ( Math . floor ( ( timeLeft / 5 ) ) ) ;
37
+ console . log ( timeLeft ) ;
38
+
39
+ localStorage . setItem ( "High Score" , JSON . stringify ( finalScore ) ) ;
40
+
41
+ finalScorePageHeader . textContent = "Your final score is " + finalScore ;
42
+ finalScoreGreeting . textContent = "Enter your initials below and click submit:" ;
43
+ finalScoreButton . textContent = "SUBMIT" ;
44
+
45
+ finalScoreButton . setAttribute ( "type" , "button" ) ;
46
+
47
+ body . appendChild ( finalScorePageHeader ) ;
48
+ finalScorePageHeader . appendChild ( finalScoreGreeting ) ;
49
+ finalScorePageHeader . appendChild ( finalScoreEntry ) ;
50
+ finalScorePageHeader . appendChild ( finalScoreButton ) ;
51
+
52
+ function storeUserDetails ( ) {
53
+ localStorage . setItem ( "User Initials" , JSON . stringify ( finalScoreEntry . value ) ) ;
54
+ scoresLink . setAttribute ( "style" , "display:block" ) ;
55
+ }
56
+ finalScoreButton . addEventListener ( "click" , storeUserDetails ) ;
57
+ }
58
+ }
59
+
14
60
// change this value to false to stop the clock
15
61
var timeRemains = true ;
16
62
@@ -26,19 +72,17 @@ function Quiz() {
26
72
clearInterval ( timeInterval ) ;
27
73
countdown . textContent = " " ;
28
74
countdown . setAttribute ( "style" , "color:red" ) ;
75
+ loadScoreScreen ( ) ;
29
76
}
30
77
}
31
78
32
79
} , 1000 ) ;
33
80
}
34
- // var question1 = null;
35
- // var body = null;
36
-
37
- var timeLeft = 31 ;
38
81
39
82
questions ( ) ;
40
83
function questions ( ) {
41
84
countdownTimer ( ) ;
85
+
42
86
question1 = document . createElement ( "h2" )
43
87
var answerList1 = document . createElement ( "button" )
44
88
var answerList2 = document . createElement ( "button" )
@@ -79,9 +123,8 @@ function Quiz() {
79
123
answerList2 . addEventListener ( "click" , incorrectResponse ) ;
80
124
answerList4 . addEventListener ( "click" , incorrectResponse ) ;
81
125
82
-
83
126
function secondQuestion ( ) {
84
- // hides the question and its answers
127
+ // hides the previous question and its answers
85
128
question1 . setAttribute ( "style" , "display:none" ) ;
86
129
87
130
var question2 = document . createElement ( "h2" )
@@ -93,7 +136,7 @@ function Quiz() {
93
136
question2 . textContent = "JavaScript uses two equals signs ( == ) to signify value equality. Three equals signs ( === ) in JavaScript signifies what?" ;
94
137
secondAnswerList1 . textContent = "the HTML and CSS are the same" ;
95
138
secondAnswerList2 . textContent = "a value of true at the child element" ;
96
- secondAnswerList3 . textContent = "value equality at the parent element " ;
139
+ secondAnswerList3 . textContent = "we can finally live at peace with one another " ;
97
140
secondAnswerList4 . textContent = "value equality and data type equality" ;
98
141
99
142
body . appendChild ( question2 ) ;
@@ -105,65 +148,63 @@ function Quiz() {
105
148
question2 . setAttribute ( "style" , "display:flex; justify-content:center; flex-direction:column" ) ;
106
149
secondAnswerList1 . setAttribute ( "style" , "disply:block" ) ;
107
150
108
- function secondCorrectResponse ( ) {
109
- totalCorrect = totalCorrect + 1 ;
110
- loadScoreScreen ( ) ;
111
- }
112
-
113
- function secondIncorrectResponse ( ) {
114
- totalCorrect = totalCorrect - 1 ;
115
- timeLeft = timeLeft - 10 ;
116
- loadScoreScreen ( ) ;
117
- }
118
-
119
151
secondAnswerList4 . addEventListener ( "click" , secondCorrectResponse ) ;
120
152
secondAnswerList2 . addEventListener ( "click" , secondIncorrectResponse ) ;
121
153
secondAnswerList3 . addEventListener ( "click" , secondIncorrectResponse ) ;
122
154
secondAnswerList1 . addEventListener ( "click" , secondIncorrectResponse ) ;
123
-
124
- function loadScoreScreen ( ) {
125
- // stops the clock and hides it
126
- timeRemains = false ;
127
- countdown . setAttribute ( "style" , "display:none" ) ;
128
- // hides the second question screen
129
- question2 . setAttribute ( "style" , "display:none" ) ;
130
-
131
- var finalScorePageHeader = document . createElement ( "h2" ) ;
132
- var finalScoreGreeting = document . createElement ( "p" ) ;
133
- var finalScoreEntry = document . createElement ( "input" ) ;
134
- var finalScoreButton = document . createElement ( "button" ) ;
135
-
136
- calculateFinalScore ( ) ;
137
-
138
- function calculateFinalScore ( ) {
139
- finalScore = totalCorrect + ( Math . floor ( ( timeLeft / 5 ) ) ) ;
140
-
141
- localStorage . setItem ( "High Score" , JSON . stringify ( finalScore ) ) ;
142
-
143
- finalScorePageHeader . textContent = "Your final score is " + finalScore ;
144
- finalScoreGreeting . textContent = "Enter your initials below:" ;
145
- finalScoreButton . textContent = "SUBMIT" ;
146
-
147
- finalScoreButton . setAttribute ( "type" , "button" ) ;
155
+
156
+ function secondCorrectResponse ( ) {
157
+ totalCorrect = totalCorrect + 1 ;
158
+ thirdQuestion ( ) ;
159
+ }
160
+
161
+ function secondIncorrectResponse ( ) {
162
+ totalCorrect = totalCorrect - 1 ;
163
+ timeLeft = timeLeft - 10 ;
164
+ thirdQuestion ( ) ;
165
+ }
166
+
167
+ function thirdQuestion ( ) {
168
+ question2 . setAttribute ( "style" , "display:none" ) ;
169
+
170
+
171
+ var thirdAnswerList1 = document . createElement ( "button" )
172
+ var thirdAnswerList2 = document . createElement ( "button" )
173
+ var thirdAnswerList3 = document . createElement ( "button" )
174
+ var thirdAnswerList4 = document . createElement ( "button" )
175
+
176
+ question3 . textContent = "The pipe symbol ( || ) can be used to evaluate two expressions in Javascript. It is used to check if..." ;
177
+ thirdAnswerList1 . textContent = "either of the two expressions is true" ;
178
+ thirdAnswerList2 . textContent = "both of the expressions are false" ;
179
+ thirdAnswerList3 . textContent = "one of the expressions has a data type of string" ;
180
+ thirdAnswerList4 . textContent = "punk rock is actually dead" ;
181
+
182
+ body . appendChild ( question3 ) ;
183
+ question3 . appendChild ( thirdAnswerList1 ) ;
184
+ question3 . appendChild ( thirdAnswerList2 ) ;
185
+ question3 . appendChild ( thirdAnswerList3 ) ;
186
+ question3 . appendChild ( thirdAnswerList4 ) ;
187
+
188
+ question3 . setAttribute ( "style" , "display:flex; justify-content:center; flex-direction:column" ) ;
189
+ thirdAnswerList1 . setAttribute ( "style" , "disply:block" ) ;
190
+
191
+ thirdAnswerList1 . addEventListener ( "click" , thirdCorrectResponse ) ;
192
+ thirdAnswerList4 . addEventListener ( "click" , thirdIncorrectResponse ) ;
193
+ thirdAnswerList2 . addEventListener ( "click" , thirdIncorrectResponse ) ;
194
+ thirdAnswerList3 . addEventListener ( "click" , thirdIncorrectResponse ) ;
148
195
149
- body . appendChild ( finalScorePageHeader ) ;
150
- finalScorePageHeader . appendChild ( finalScoreGreeting ) ;
151
- finalScorePageHeader . appendChild ( finalScoreEntry ) ;
152
- finalScorePageHeader . appendChild ( finalScoreButton ) ;
153
-
154
- function storeUserDetails ( event ) {
155
- event . preventDefault ( ) ;
156
- localStorage . setItem ( "User Initials" , JSON . stringify ( finalScoreEntry . value ) ) ;
157
- }
158
- finalScoreButton . addEventListener ( "click" , storeUserDetails ) ;
159
- }
160
- }
196
+ function thirdCorrectResponse ( ) {
197
+ totalCorrect = totalCorrect + 1 ;
198
+ loadScoreScreen ( ) ;
199
+ }
200
+
201
+ function thirdIncorrectResponse ( ) {
202
+ totalCorrect = totalCorrect - 1 ;
203
+ timeLeft = timeLeft - 10 ;
204
+ loadScoreScreen ( ) ;
161
205
}
162
206
}
207
+ }
208
+ }
163
209
}
164
- }
165
-
166
- // TO DO LIST:
167
- // IT'S NOT KEEPING SCORE CORRECTLY!
168
- // have to add another couple questions
169
- // have to link to the scores page (at least from the final page)
210
+ }
0 commit comments