@@ -27,34 +27,50 @@ window.onload = () => {
27
27
} ;
28
28
const snippets = {
29
29
Functions : [
30
- `type to start ` ,
30
+ `type: functions ` ,
31
31
`function reverse(s: string): string;` ,
32
32
`function playSound(x: () => void) {x();}` ,
33
33
`const compact = (arr: any[]) => arr.filter(Boolean);` ,
34
34
`let oddNumbers:number[] = myArr.filter( (n:number) => n % 2 == 0 )` ,
35
+ `function firstElement2<Type extends any[]>(arr: Type) {return arr[0];}` ,
36
+ `topic complete return to menu!` ,
35
37
] ,
36
38
Casting : [
37
- `type to start` ,
39
+ `type: casting` ,
40
+ `const currTopic = topic as options` ,
38
41
`const winSound = document.querySelector("#win_sound") as HTMLAudioElement;` ,
39
42
`let input = document.querySelector('input[type="text"]') as HTMLInputElement;` ,
40
43
`const XP = document.querySelector("#xp") as HTMLParagraphElement;` ,
44
+ `topic complete return to menu!` ,
41
45
] ,
42
46
Interfaces : [
43
- `type to start ` ,
47
+ `type: interfaces ` ,
44
48
`interface Person { name: string; age: number;}` ,
45
49
`interface PaintOptions { shape: Shape; xPos?: number; yPos?: number;}` ,
50
+ `interface CallOrConstruct {new (s: string): Date; (n?: number): number;}` ,
51
+ `topic complete return to menu!` ,
46
52
] ,
47
53
Generics : [
48
- `type to start ` ,
54
+ `type: generics ` ,
49
55
`function identity<Type>(arg: Type): Type {return arg;}` ,
50
56
`let myIdentity: <Type>(arg: Type) => Type = identity;` ,
57
+ `function firstElem<Type>(arr: Type[]): Type | undefined {return arr[0];}` ,
58
+ `topic complete return to menu!` ,
51
59
] ,
52
60
} ;
53
61
// key event listener
54
62
document . addEventListener ( "keydown" , ( event ) => {
55
63
let currPress = event . key ;
56
64
const frontOfStackLetter = frontOfStackElem . innerHTML ;
57
65
currPress = convertSpecial ( currPress ) ;
66
+ if ( currPress === "Enter" ) {
67
+ ul . classList . remove ( "hidden" ) ;
68
+ round ++ ;
69
+ roundInfo . innerHTML = `${ topic } : Round ${ String ( round ) } ` ;
70
+ clearList ( starUL ) ;
71
+ statDisplay . innerHTML = "" ;
72
+ return ;
73
+ }
58
74
if ( currPress === frontOfStackLetter && frontOfStackElem !== null ) {
59
75
//correct key
60
76
keyEffect ( frontOfStackElem , true ) ;
@@ -84,6 +100,10 @@ topicSelectors.forEach((btn) => {
84
100
form === null || form === void 0 ? void 0 : form . classList . add ( "hidden" ) ;
85
101
menu === null || menu === void 0 ? void 0 : menu . classList . remove ( "hidden" ) ;
86
102
footer === null || footer === void 0 ? void 0 : footer . classList . add ( "hidden" ) ;
103
+ clearList ( ul ) ;
104
+ nextSet ( ) ;
105
+ ul . classList . remove ( "hidden" ) ;
106
+ roundInfo . innerHTML = `${ topic } : Warm up 🙌` ;
87
107
} ) ;
88
108
} ) ;
89
109
menu === null || menu === void 0 ? void 0 : menu . addEventListener ( "click" , ( ) => {
@@ -121,8 +141,6 @@ function keyEffect(frontOfStackElem, correct) {
121
141
//start timer when first correct key entered on new round
122
142
if ( correct && timerStarted === false ) {
123
143
timer . start ( ) ;
124
- clearList ( starUL ) ;
125
- statDisplay . innerHTML = "" ;
126
144
errorcount = 0 ;
127
145
timerStarted = true ;
128
146
}
@@ -131,11 +149,10 @@ function moveToNext(frontOfStackElem) {
131
149
if ( frontOfStackElem . nextElementSibling === null ) {
132
150
displayStats ( ) ;
133
151
frontOfStackElem = nextSet ( ) ;
152
+ ul . classList . add ( "hidden" ) ;
134
153
timer . stop ( ) ;
135
154
timer . reset ( ) ;
136
155
timerStarted = false ;
137
- round ++ ;
138
- roundInfo . innerHTML = `${ topic } : Round ${ String ( round ) } ` ;
139
156
return frontOfStackElem ;
140
157
}
141
158
return frontOfStackElem . nextElementSibling ;
@@ -164,14 +181,15 @@ function displayStats() {
164
181
runningScore += score ;
165
182
XP . innerHTML = `${ String ( Math . ceil ( runningScore ) ) } XP` ;
166
183
if ( score > 1500 ) {
167
- statDisplay . innerHTML = `${ speed } words a minute!${ speed > 40 ? "🔥🔥" : "" } ${ accuracy } % accuracy ${ accuracy > 95 ? "🎯🎯🎯" : "" } , +${ score } xp` ;
184
+ statDisplay . innerHTML = `${ speed } words a minute!${ speed > 40 ? "🔥🔥" : "" } ${ accuracy } % accuracy ${ accuracy > 95 ? "🎯🎯🎯" : "" } +${ score } xp` ;
168
185
winSound . currentTime = 0 ;
169
186
winSound . play ( ) ;
170
187
snippetIndex ++ ;
171
188
}
172
189
else {
173
190
statDisplay . innerHTML = `Failed 😰. ${ speed } words per minute. ${ accuracy } % accuracy. Try again!` ;
174
191
}
192
+ statDisplay . innerHTML += "</br></br>'Enter' to continue..." ;
175
193
}
176
194
function getStats ( ) {
177
195
const secondsExpired = timer . getTime ( ) / 1000 ;
@@ -233,6 +251,8 @@ function reset() {
233
251
errorcount = 0 ;
234
252
snippetIndex = 0 ;
235
253
runningScore = 0 ;
254
+ timer . stop ( ) ;
255
+ timer . reset ( ) ;
236
256
timerStarted = false ;
237
257
clearList ( ul ) ;
238
258
clearList ( starUL ) ;
0 commit comments