File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 52
52
</ body >
53
53
< script >
54
54
let input = document . querySelector ( 'input.guess' )
55
+ let wordToBeGuessed
55
56
56
57
document . querySelector ( 'button#confirmGuess' )
57
58
. addEventListener (
58
59
'click' ,
59
- function ( e ) {
60
- let inputIsValid = input . value . toLower >= 'a' && input . value . toLower <= 'z'
60
+ function ( ) {
61
+ let guess = input . value . toLowerCase ( )
62
+ let inputIsValid = guess >= 'a' && guess <= 'z'
63
+ let wordElement = document . querySelector ( 'div#word' )
61
64
62
65
if ( ! inputIsValid ) {
63
66
input . classList . add ( 'invalid' )
67
+ return
68
+ }
69
+
70
+ for ( let i = 0 ; i < wordToBeGuessed . length ; i ++ ) {
71
+ if ( wordToBeGuessed [ i ] === guess ) {
72
+ let letterToShow = wordElement . getElementsByTagName ( 'span' ) . item ( i )
73
+ letterToShow . setAttribute ( 'x-data' , '{ hidden:false }' )
74
+ }
64
75
}
65
76
}
66
77
)
110
121
Math . random ( ) * words . length
111
122
) ;
112
123
113
- return words [ index ] ;
124
+ return wordToBeGuessed = words [ index ] ;
114
125
}
115
126
116
127
function hiddenChar ( char ) {
You can’t perform that action at this time.
0 commit comments