@@ -7,12 +7,14 @@ export class Quiz {
77 this . QUESTION_VALUE = 100 ;
88 this . QUESTIONS_AMOUNT = dataQA . length ;
99 this . barPercetage = 0 ;
10+ this . streakPoints = 0 ;
11+ this . timePoints = 0 ;
1012 this . score = 0 ;
1113 this . answer = "" ;
1214 this . canClick = true ;
1315 this . noOfCorrect = 0 ;
1416 this . TOTAL_CORRECT = 0 ;
15-
17+
1618 this . correctStreak = 0 ; // Tracks consecutive correct answers
1719 this . startTime = 0 ; // Stores the start time of each question
1820 // runs here because we want to load the first round of questions
@@ -92,9 +94,13 @@ export class Quiz {
9294 this . _updateCorrectCount ( ) ;
9395 this . calculateTimeBonus ( ) ;
9496 this . updateStreak ( ) ;
97+ document . getElementById ( 'score' ) . classList . add ( 'green-score' ) ;
98+ document . getElementById ( 'addPoints' ) . style . display = 'block' ;
9599 } else {
96100 p . parentElement . classList . add ( "incorrect" ) ;
97101 this . score -= this . QUESTION_VALUE ;
102+ document . getElementById ( 'score' ) . classList . add ( 'red-score' ) ;
103+ document . getElementById ( 'subPoints' ) . style . display = 'block' ;
98104 }
99105
100106 document . getElementById ( "score" ) . textContent = this . score ;
@@ -106,6 +112,10 @@ export class Quiz {
106112 this . canClick = true ;
107113 p . parentElement . classList . remove ( "incorrect" ) ;
108114 p . parentElement . classList . remove ( "correct" ) ;
115+ document . getElementById ( 'score' ) . classList . remove ( 'green-score' ) ;
116+ document . getElementById ( 'score' ) . classList . remove ( 'red-score' ) ;
117+ document . getElementById ( 'subPoints' ) . style . display = 'none' ;
118+ document . getElementById ( 'addPoints' ) . style . display = 'none' ;
109119 } , 600 ) ;
110120 }
111121
@@ -118,10 +128,13 @@ export class Quiz {
118128
119129 if ( elapsed <= 1000 ) {
120130 this . score += 1000 ;
121- } else if ( elapsed <= 5000 ) {
131+ this . timePoints = 1000 ;
132+ } else if ( elapsed <= 5000 ) {
122133 this . score += 500 ;
134+ this . timePoints = 500 ;
123135 } else if ( elapsed <= 10000 ) {
124136 this . score += 100 ;
137+ this . timePoints = 100 ;
125138 }
126139 }
127140
@@ -130,18 +143,100 @@ export class Quiz {
130143
131144 if ( this . correctStreak === 2 ) {
132145 this . score += 200 ;
146+ this . streakPoints = 300 ;
147+ this . bonusPoints = this . streakPoints + this . timePoints
148+ this . displayText = "+" + this . bonusPoints ;
149+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
133150 } else if ( this . correctStreak === 3 ) {
134151 this . score += 300 ;
135- } else if ( this . correctStreak === 5 ) {
152+ this . streakPoints = 400 ;
153+ this . bonusPoints = this . streakPoints + this . timePoints
154+ this . displayText = "+" + this . bonusPoints ;
155+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
156+ } else if ( this . correctStreak === 4 ) {
157+ this . score += 300 ;
158+ this . streakPoints = 400 ;
159+ this . bonusPoints = this . streakPoints + this . timePoints
160+ this . displayText = "+" + this . bonusPoints ;
161+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
162+ } else if ( this . correctStreak === 5 ) {
163+ this . score += 800 ;
164+ this . streakPoints = 900 ;
165+ this . bonusPoints = this . streakPoints + this . timePoints
166+ this . displayText = "+" + this . bonusPoints ;
167+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
168+ } else if ( this . correctStreak === 6 ) {
169+ this . score += 800 ;
170+ this . streakPoints = 900 ;
171+ this . bonusPoints = this . streakPoints + this . timePoints
172+ this . displayText = "+" + this . bonusPoints ;
173+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
174+ } else if ( this . correctStreak === 7 ) {
175+ this . score += 800 ;
176+ this . streakPoints = 900 ;
177+ this . bonusPoints = this . streakPoints + this . timePoints
178+ this . displayText = "+" + this . bonusPoints ;
179+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
180+ } else if ( this . correctStreak === 8 ) {
181+ this . score += 800 ;
182+ this . streakPoints = 900 ;
183+ this . bonusPoints = this . streakPoints + this . timePoints
184+ this . displayText = "+" + this . bonusPoints ;
185+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
186+ } else if ( this . correctStreak === 9 ) {
136187 this . score += 800 ;
137- } else if ( this . correctStreak === 10 ) {
188+ this . streakPoints = 900 ;
189+ this . bonusPoints = this . streakPoints + this . timePoints
190+ this . displayText = "+" + this . bonusPoints ;
191+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
192+ } else if ( this . correctStreak === 10 ) {
138193 this . score += 1200 ;
194+ this . streakPoints = 1300 ;
195+ this . bonusPoints = this . streakPoints + this . timePoints
196+ this . displayText = "+" + this . bonusPoints ;
197+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
198+ } else if ( this . correctStreak === 11 ) {
199+ this . score += 1200 ;
200+ this . streakPoints = 1300 ;
201+ this . bonusPoints = this . streakPoints + this . timePoints
202+ this . displayText = "+" + this . bonusPoints ;
203+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
204+ } else if ( this . correctStreak === 12 ) {
205+ this . score += 1200 ;
206+ this . streakPoints = 1300 ;
207+ this . bonusPoints = this . streakPoints + this . timePoints
208+ this . displayText = "+" + this . bonusPoints ;
209+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
210+ } else if ( this . correctStreak === 13 ) {
211+ this . score += 1200 ;
212+ this . streakPoints = 1300 ;
213+ this . bonusPoints = this . streakPoints + this . timePoints
214+ this . displayText = "+" + this . bonusPoints ;
215+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
216+ } else if ( this . correctStreak === 14 ) {
217+ this . score += 1200 ;
218+ this . streakPoints = 1300 ;
219+ this . bonusPoints = this . streakPoints + this . timePoints
220+ this . displayText = "+" + this . bonusPoints ;
221+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
139222 } else if ( this . correctStreak === 15 ) {
140223 this . score += 1500 ;
224+ this . streakPoints = 1600 ;
225+ this . bonusPoints = this . streakPoints + this . timePoints
226+ this . displayText = "+" + this . bonusPoints ;
227+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
141228 } else if ( this . correctStreak > 15 ) {
142229 this . score += 1500 ; // Add 1500 points for each additional correct answer beyond 15
143- } else {
144- this . correctStreak = 1 ; // Reset the streak if the answer is not consecutive
230+ this . streakPoints = 1600 ;
231+ this . bonusPoints = this . streakPoints + this . timePoints
232+ this . displayText = "+" + this . bonusPoints ;
233+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
234+ } else if ( this . correctStreak = 1 ) {
235+ this . score += 100 ; // Reset the streak if the answer is not consecutive
236+ this . streakPoints = 200 ;
237+ this . bonusPoints = this . streakPoints + this . timePoints
238+ this . displayText = "+" + this . bonusPoints ;
239+ document . getElementById ( "addPoints" ) . textContent = this . displayText ;
145240 }
146241 }
147242}
0 commit comments