Skip to content

Commit 3cc429f

Browse files
committed
Show guessed chars (wip)
1 parent 36a4110 commit 3cc429f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

index.html

+14-3
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,26 @@
5252
</body>
5353
<script>
5454
let input = document.querySelector('input.guess')
55+
let wordToBeGuessed
5556

5657
document.querySelector('button#confirmGuess')
5758
.addEventListener(
5859
'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')
6164

6265
if (!inputIsValid) {
6366
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+
}
6475
}
6576
}
6677
)
@@ -110,7 +121,7 @@
110121
Math.random() * words.length
111122
);
112123

113-
return words[index];
124+
return wordToBeGuessed = words[index];
114125
}
115126

116127
function hiddenChar(char) {

0 commit comments

Comments
 (0)