-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcards.js
49 lines (36 loc) · 1.21 KB
/
cards.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
'use strict';
let terms;
let abbr;
let long;
const guess = document.querySelector("p");
const abbreviation = document.querySelector("abbr");
const rotate = () => {
({ abbr, long } = terms[Math.floor(Math.random() * terms.length)]);
guess.classList.remove("correct");
guess.classList.remove("wrong");
guess.textContent = "";
abbreviation.textContent = abbr;
}
const correct = () => guess.classList.add("correct");
async function init() {
terms = await (await fetch("terms/cysa.json")).json();
document.querySelector("body").addEventListener("click", e => rotate())
abbreviation.addEventListener("click", e => {
e.stopPropagation();
guess.classList.add("wrong");
guess.textContent = long;
})
guess.addEventListener("click", e => e.stopPropagation());
guess.addEventListener("input", e => {
console.dir(e)
const typed = e.target.textContent.toLowerCase().replace(",", "").replace("&", "");
const term = long.toLowerCase().replace(",", "").replace("&", "");
guess.classList.remove("wrong");
if (typed == term) {
guess.textContent = long;
correct();
}
});
rotate();
}
init();