-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs_logic.js
64 lines (47 loc) · 1.63 KB
/
inputs_logic.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
60
61
62
63
64
// LÓGICA DOS ESTADOS --->
function testInputsLetters(inputs, slots) {
for(let i = 0; i < slots.length; i++) {
if(slots[i].userLetter === '') {
slots[i].status = 'empty'
} else if (slots[i].userLetter === slots[i].rightLetter) {
slots[i].status = 'right'
blockInput(inputs[i])
} else {
let match = false
for(let a = 0; a < slots.length; a++) {
if(slots[a].rightLetter === slots[i].userLetter && slots[a].userLetter !== slots[a].rightLetter && slots[a] !== slots[i]) {
match = true
}
match ? slots[i].status = 'misplaced' : slots[i].status = 'wrong'
}
}
}
}
// LÓGICA DAS CORES --->
function inputsColor(inputs, slots) {
for(let i in slots) {
switch(slots[i].status) {
case 'right':
inputs[i].setAttribute('class', 'input-letter --letter-right')
break
case 'misplaced':
inputs[i].setAttribute('class', 'input-letter --letter-misplaced')
break
case 'wrong':
inputs[i].setAttribute('class', 'input-letter --letter-wrong')
break
default:
inputs[i].setAttribute('class', 'input-letter')
}
}
}
export function inputsLogic(elem, index, inputs, slots) {
elem.value = elem.value.toUpperCase()
slots[index].userLetter = elem.value
testInputsLetters(inputs, slots)
inputsColor(inputs, slots)
}
// BLOQUEAR UM INPUT --->
export function blockInput(elem) {
elem.setAttribute('disabled', 'disabled')
}