-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
59 lines (47 loc) · 1.72 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const shuffleArray = (values) => {
let index = values.length;
let randomIndex;
while (index != 0) {
randomIndex = Math.floor(Math.random() * index);
index--;
[values[index], values[randomIndex]] = [values[randomIndex], values[index]];
}
return values;
};
const alphabet = [];
for (let i = 65; i <= 90; i++) {
alphabet.push(String.fromCharCode(i));
}
let unsorted = shuffleArray(alphabet);
let index = 0;
const addUsedLetter = (index) => {
if (index === 0) {
const usedLetters = document.getElementById('used-letters');
usedLetters.classList.remove('hidden');
const currentLetter = document.getElementById('current-letter');
currentLetter.classList.remove('hidden');
return unsorted[index];
}
if (index === 25) {
const generate = document.getElementById('generate');
generate.disabled = true;
}
return `, ${unsorted[index]}`;
};
const generateLetter = () => {
document.querySelector('#current-letter span').textContent = unsorted[index];
document.querySelector('#used-letters span').textContent += addUsedLetter(index);
index++;
};
const resetLetters = () => {
const usedLetters = document.getElementById('used-letters');
const currentLetter = document.getElementById('current-letter');
const usedLettersSpan = document.querySelector('#used-letters span');
usedLetters.classList.add('hidden');
currentLetter.classList.add('hidden');
usedLettersSpan.textContent = '';
index = 0;
unsorted = shuffleArray(alphabet);
const generate = document.getElementById('generate');
generate.disabled = false;
};