-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_alphabet.js
107 lines (69 loc) · 1.95 KB
/
script_alphabet.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
score = 0
const alpahbet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
letter1 = -1;
letter2 = -1;
timer = 5;
var timer_interval = setInterval(timer_func, 1000);
window.onload = function () {
document.getElementById("timer").innerHTML = timer;
set_letters();
};
function update_score(correct) {
timer = 6;
if (correct) {
score += 1;
notification_color = "darkseagreen"
} else {
score = 0;
notification_color = "tomato"
error_msg();
}
document.body.style.backgroundColor = notification_color;
setTimeout(() => {
document.body.style.backgroundColor = "darkgray";
}, 500);
document.getElementById("score").innerHTML = score;
};
function set_letters() {
do {
letter1 = Math.floor(Math.random() * 26)
letter2 = Math.floor(Math.random() * 26)
}
while (letter1 == letter2);
document.getElementById("letter1").innerHTML = alpahbet[letter1];
document.getElementById("letter2").innerHTML = alpahbet[letter2];
}
function letter1_click() {
if (letter1 < letter2) {
update_score(true);
} else {
update_score(false)
}
set_letters();
}
function letter2_click() {
if (letter1 < letter2) {
update_score(false);
} else {
update_score(true)
}
set_letters();
}
function error_msg() {
if (letter1 < letter2) {
var msg = alpahbet[letter1] + " before " + alpahbet[letter2]
} else {
var msg = alpahbet[letter2] + " before " + alpahbet[letter1]
}
document.getElementById("errorlist").innerHTML = document.getElementById("errorlist").innerHTML + "<br>" + msg
};
function timer_func() {
timer -= 1;
document.getElementById("timer").innerHTML = timer;
console.log(timer)
if (timer < 1) {
update_score(false);
set_letters();
timer = 6;
}
}