-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiragana.html
133 lines (126 loc) · 6.48 KB
/
hiragana.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hiragana Practice</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
#character {
font-size: 40px;
font-weight: bold;
margin-bottom: 20px;
}
input {
padding: 10px;
font-size: 16px;
}
button {
padding: 10px 20px;
font-size: 16px;
margin: 10px;
}
#feedback {
font-size: 18px;
margin-top: 10px;
width: 200px;
word-wrap: break-word;
margin: auto;
}
</style>
</head>
<body>
<div id="character"></div>
<br>
<form id="practice-form">
<input type="text" id="answer" placeholder="Enter romaji">
</form>
<br>
<p id="feedback"></p>
<script>
const charMap = [
{ question: "あ", answer: "a" }, { question: "い", answer: "i" }, { question: "う", answer: "u" }, { question: "え", answer: "e" }, { question: "お", answer: "o" },
{ question: "か", answer: "ka" }, { question: "き", answer: "ki" }, { question: "く", answer: "ku" }, { question: "け", answer: "ke" }, { question: "こ", answer: "ko" },
{ question: "が", answer: "ga" }, { question: "ぎ", answer: "gi" }, { question: "ぐ", answer: "gu" }, { question: "げ", answer: "ge" }, { question: "ご", answer: "go" },
{ question: "さ", answer: "sa" }, { question: "し", answer: "shi" }, { question: "す", answer: "su" }, { question: "せ", answer: "se" }, { question: "そ", answer: "so" },
{ question: "ざ", answer: "za" }, { question: "じ", answer: "ji" }, { question: "ず", answer: "zu" }, { question: "ぜ", answer: "ze" }, { question: "ぞ", answer: "zo" },
{ question: "た", answer: "ta" }, { question: "ち", answer: "chi" }, { question: "つ", answer: "tsu" }, { question: "て", answer: "te" }, { question: "と", answer: "to" },
{ question: "だ", answer: "da" }, { question: "ぢ", answer: "ji" }, { question: "づ", answer: "zu" }, { question: "で", answer: "de" }, { question: "ど", answer: "do" },
{ question: "な", answer: "na" }, { question: "に", answer: "ni" }, { question: "ぬ", answer: "nu" }, { question: "ね", answer: "ne" }, { question: "の", answer: "no" },
{ question: "は", answer: "ha" }, { question: "ひ", answer: "hi" }, { question: "ふ", answer: "fu" }, { question: "へ", answer: "he" }, { question: "ほ", answer: "ho" },
{ question: "ば", answer: "ba" }, { question: "び", answer: "bi" }, { question: "ぶ", answer: "bu" }, { question: "べ", answer: "be" }, { question: "ぼ", answer: "bo" },
{ question: "ぱ", answer: "pa" }, { question: "ぴ", answer: "pi" }, { question: "ぷ", answer: "pu" }, { question: "ぺ", answer: "pe" }, { question: "ぽ", answer: "po" },
{ question: "わ", answer: "wa" }, { question: "を", answer: "wo" }, { question: "ん", answer: "n" },
{ question: "きゃ", answer: "kya" }, { question: "きゅ", answer: "kyu" }, { question: "きょ", answer: "kyo" },
{ question: "しゃ", answer: "sha" }, { question: "しゅ", answer: "shu" }, { question: "しょ", answer: "sho" },
{ question: "ちゃ", answer: "cha" }, { question: "ちゅ", answer: "chu" }, { question: "ちょ", answer: "cho" },
{ question: "にゃ", answer: "nya" }, { question: "にゅ", answer: "nyu" }, { question: "にょ", answer: "nyo" },
{ question: "ひゃ", answer: "hya" }, { question: "ひゅ", answer: "hyu" }, { question: "ひょ", answer: "hyo" },
{ question: "みゃ", answer: "mya" }, { question: "みゅ", answer: "myu" }, { question: "みょ", answer: "myo" },
{ question: "りゃ", answer: "rya" }, { question: "りゅ", answer: "ryu" }, { question: "りょ", answer: "ryo" }
];
let shuffledCharacters = [...charMap];
shuffleArray(shuffledCharacters);
let currentIndex = 0;
const answerEl = document.getElementById("answer");
const feedbackEl = document.getElementById("feedback");
const characterEl = document.getElementById("character");
let timeout = null;
function checkAnswer(isEnter) {
let answer = answerEl.value.toLowerCase();
if (answer === "?") {
feedbackEl.innerText = "Enter romaji '" + shuffledCharacters[currentIndex].answer + "' to continue";
return;
}
if (answer === shuffledCharacters[currentIndex].answer) {
const t = updateCharacter(false);
answerEl.value = "";
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {feedbackEl.innerText = "";}, t);
} else if (isEnter) {
feedbackEl.innerText = `Incorrect. Try again.`;
}
}
function firstTime() {
document.getElementById("practice-form").addEventListener("submit", function(event) {
event.preventDefault();
checkAnswer(true);
});
answerEl.addEventListener("input", function (event) {
checkAnswer(false)
});
updateCharacter(true);
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function updateCharacter(isFirstTime) {
let rv = 500;
if (isFirstTime) {
feedbackEl.innerText = "Answers are checked as you enter them or when you press enter. Type '?' to get the correct answer.";
}
else if (++currentIndex >= shuffledCharacters.length) {
shuffleArray(shuffledCharacters);
currentIndex = 0;
feedbackEl.innerText = "You have completed the set! Restarting...";
rv *= 2;
}
else {
feedbackEl.innerText = "Correct!";
}
characterEl.innerText = shuffledCharacters[currentIndex].question;
return rv;
}
firstTime();
</script>
</body>
</html>