-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordViewerQuiz.js
More file actions
174 lines (133 loc) · 5.86 KB
/
WordViewerQuiz.js
File metadata and controls
174 lines (133 loc) · 5.86 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// function showWordViewerQuiz() {
// const phraseList = [
// ["シンリョクの季節", "新緑"],
// ["iphoneをジュウデンする", "充電"],
// ["先生にソウダンする", "相談"],
// ["アキバレの空", "秋晴れ"],
// ["時間をサイテキに使う", "最適"],
// ["コウカテキな方法", "効果的"],
// ["ジュンビが整う", "準備"],
// ["レイセイな判断", "冷静"],
// ["テンコウが変わる", "天候"],
// ["キョウイクの問題", "教育"],
// ["カイシャの代表", "会社"],
// ["ショウライの夢", "将来"],
// ["トショカンに行く", "図書館"],
// ["カイケツ策を考える", "解決"],
// ["ジョウキョウを説明する", "状況"],
// ["コウガクの発展", "工学"],
// ["シンガッキが始まる", "新学期"],
// ["セイカクを知る", "性格"],
// ["カンガエカタを学ぶ", "考え方"],
// ["レキシを勉強する", "歴史"],
// ["センタクの自由", "選択"],
// ["ジッケンを行う", "実験"],
// ["シュウカンを守る", "習慣"],
// ["スイエイの練習", "水泳"],
// ["ユウキを持つ", "勇気"],
// ["ゲンジツを見る", "現実"],
// ["セイセキが上がる", "成績"],
// ["タンサンを飲む", "炭酸"],
// ["カンキョウを守る", "環境"],
// ["コウソクを守る", "校則"]
// ];
function showWordViewerQuiz() {
const phraseList = [
["シンリョクの季節", "新緑"],
["iphoneをジュウデンする", "充電"],
["カンキョウを守る", "環境"],
["コウソクを守る", "校則"]
];
let phraseListIncorrect = [];
let currentPhraseIndex = 0;
const interactedPhrases = [];
function updatePhraseLabel() {
const phraseLabel = document.getElementById("phrase-label");
if (currentPhraseIndex >= 0 && currentPhraseIndex < phraseList.length) {
phraseLabel.textContent = phraseList[currentPhraseIndex][0];
} else {
phraseLabel.textContent = "No more words";
if (phraseListIncorrect.length === 0) {
displayPassMessageWithDelay();
} else {
displayInteractedPhrasesWithDelay();
}
}
}
function displayInteractedPhrases() {
const resultDiv = document.getElementById('phrase-label');
let tableHtml = "<table><tr><th>Phrase</th><th>Kanji</th></tr>";
for (const phrase of interactedPhrases) {
tableHtml += `<tr><td>${phrase[0]}</td><td>${phrase[1]}</td></tr>`;
}
tableHtml += "</table>";
resultDiv.innerHTML = tableHtml;
resultDiv.classList.remove('hidden');
}
function displayInteractedPhrasesWithDelay() {
const phraseLabel = document.getElementById("phrase-label");
phraseLabel.innerHTML = "<span class='typing'>結果は...</span>";
setTimeout(displayInteractedPhrases, 3000);
}
function displayPassMessageWithDelay() {
const phraseLabel = document.getElementById("phrase-label");
phraseLabel.innerHTML = "<span class='typing'>合格!!</span><br>";
setTimeout(function() {
phraseLabel.innerHTML = "合格!!<br>メニューへ";
}, 3000);
}
function checkAnswer() {
const value = document.getElementById('example').value;
const resultDiv = document.getElementById('result');
resultDiv.classList.remove('hidden');
if (value == 2) {
resultDiv.innerHTML = "<知らない 知ってる!>";
} else if (value == 1 || value == 3) {
resultDiv.innerHTML = phraseList[currentPhraseIndex][1];
if (value == 1) {
interactedPhrases.push(phraseList[currentPhraseIndex]);
phraseListIncorrect.push(phraseList[currentPhraseIndex]); // Save incorrect answers
}
if (currentPhraseIndex == phraseList.length - 1) {
if (phraseListIncorrect.length === 0) {
displayPassMessageWithDelay();
} else {
displayInteractedPhrasesWithDelay();
document.getElementById('example').style.display = 'none';
document.getElementById('revenge-button').style.display = 'block';
}
}
currentPhraseIndex = Math.min(currentPhraseIndex + 1, phraseList.length);
} else {
resultDiv.innerHTML = "let's swipe";
}
}
function resetSlider() {
document.getElementById('example').value = 2;
updatePhraseLabel();
document.getElementById('result').classList.add('hidden');
}
function retryIncorrectPhrases() {
if (phraseListIncorrect.length > 0) {
phraseList.length = 0;
for (const phrase of phraseListIncorrect) {
phraseList.push(phrase);
}
phraseListIncorrect = [];
currentPhraseIndex = 0;
interactedPhrases.length = 0;
document.getElementById('example').style.display = 'block';
document.getElementById('revenge-button').style.display = 'none';
resetSlider();
updatePhraseLabel();
}
}
document.getElementById('example').addEventListener('input', checkAnswer);
document.getElementById('example').addEventListener('change', resetSlider);
document.getElementById('revenge-button').addEventListener('click', retryIncorrectPhrases);
updatePhraseLabel();
}
function backMenu() {
window.location.href = 'WordViewer.html';
}
document.addEventListener('DOMContentLoaded', showWordViewerQuiz);