-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKanaLearn.js
60 lines (49 loc) · 1.26 KB
/
KanaLearn.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
class KanaLearn {
constructor(hiragana, katakana) {
this.hiragana = hiragana;
this.katakana = katakana;
this.currentKana = "";
let kanaType = localStorage.getItem("kana_type");
let onlyMonographs = localStorage.getItem("monographs");
if(kanaType) {
this.kanaType = kanaType
} {
setLS("kana_type", "hiragana");
this.kanaType = "hiragana"
}
if (onlyMonographs) {
this.onlyMonographs = onlyMonographs;
} else {
setLS("monographs", false);
this.onlyMonographs = false;
}
}
correctCheck(inputValue){
console.log(inputValue);
if (this.currentKana == this[this.kanaType][inputValue]) {
return true;
}
return false;
}
getRandomKana() {
let letters = Object.values(this[this.kanaType]);
if (!this.onlyMonographs) {
letters = letters.filter(letter => letter.length === 1);
}
const randomIndex = Math.floor(Math.random() * letters.length);
this.currentKana = letters[randomIndex];
return this.currentKana;
}
toggleOnlyMonographs() {
setLS("monographs", !this.onlyMonographs);
this.onlyMonographs = !this.onlyMonographs;
}
changeKanaType(kanaType) {
setLS("kana_type", kanaType);
this.kanaType = kanaType;
}
}
function setLS(key, value) {
localStorage.setItem(key, value);
}
export default KanaLearn;