1+ window . addEventListener ( 'load' , init ) ;
2+
3+ let time = 10 ;
4+ let score = 0 ;
5+ let isplaying ;
6+
7+
8+
9+ const WordInput = document . querySelector ( '#label' ) ;
10+ const Currentword = document . querySelector ( '#currentword' ) ;
11+ const seconds = document . querySelector ( '#number' ) ;
12+ const message = document . querySelector ( '#message' ) ;
13+ const TimeDisplay = document . querySelector ( '#time' ) ;
14+ const ScoreDispaly = document . querySelector ( '#score' ) ;
15+
16+
17+
18+ const words = [
19+ 'jacob stood on his tiptoes' ,
20+ 'the car turned the corner' ,
21+ 'kelly twirled in circles' ,
22+ 'aaron made a picture' ,
23+ 'the staff performed well' ,
24+ 'white shirt always looks sharp' ,
25+ 'the cat and the dog yowled' ,
26+ 'open the jar carefully' ,
27+ 'make the best of things' ,
28+ 'the cat and dog ate' ,
29+ 'i opened all the gift' ,
30+ 'when i go to the beach' ,
31+ 'i went to the beach' ,
32+ 'i will shop at the store' ,
33+ 'wolf ate steak at the zoo' ,
34+ 'they have to be short' ,
35+ 'they have to be long'
36+
37+ ] ;
38+ function init ( ) {
39+ showWords ( words ) ;
40+ WordInput . addEventListener ( 'input' , Startmatch )
41+ setInterval ( countdown , 1000 ) ;
42+ setInterval ( checkstatus , 50 )
43+
44+ }
45+
46+ function Startmatch ( ) {
47+ if ( match ( ) ) {
48+ isplaying = true ;
49+ time = 11 ;
50+ showWords ( words ) ;
51+ WordInput . value = '' ;
52+ score ++ ;
53+ }
54+ if ( score == - 1 ) {
55+ ScoreDispaly . innerHTML = 0
56+
57+ } else {
58+ ScoreDispaly . innerHTML = score
59+ }
60+
61+ }
62+
63+
64+ function match ( ) {
65+ if ( WordInput . value == Currentword . innerHTML ) {
66+ message . innerHTML = 'Correct!!'
67+ return true ;
68+ } else {
69+ message . innerHTML = '' ;
70+ return false ;
71+ }
72+
73+ }
74+ function showWords ( words ) {
75+ const randIndex = Math . floor ( Math . random ( ) * words . length ) ;
76+ Currentword . innerHTML = words [ randIndex ] ;
77+ }
78+
79+ function countdown ( ) {
80+ if ( time > 0 ) {
81+ time -- ;
82+
83+ } else if ( time == 0 ) {
84+ isplaying = false ;
85+ }
86+ TimeDisplay . innerHTML = time ;
87+ }
88+ function checkstatus ( ) {
89+ if ( ! isplaying && time == 0 ) {
90+ message . innerHTML = "Game over!!! Better Luck Next Time" ;
91+ score = - 1 ;
92+ }
93+ }
0 commit comments