-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFuncQuizGame.js
More file actions
259 lines (217 loc) · 8.18 KB
/
FuncQuizGame.js
File metadata and controls
259 lines (217 loc) · 8.18 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
function displayQuiz() {
document.getElementById('container-div').style.display = 'none';
var boxQuiz = document.getElementById('box-practice');
if (boxQuiz.style.display === 'none')
boxQuiz.style.display = 'block';
}
function check(x, ans) {
if (x == 0 && ans == "a") return true;
else if (x == 1 && ans == "b") return true;
else if (x == 2 && ans == "c") return true;
else if (x == 3 && ans == "d") return true;
else return false;
}
function checkInput(ans) {
if (ans == "a" || ans == "b" || ans == "c" || ans == "d")
return true;
else
return false;
}
function resetPractice() {
document.getElementById('practice-container').textContent = '';
}
function printResult(check) {
if (check) {
addDivToContainer(arr[x] + " is correct", "practice-container", "correct");
}
else {
addDivToContainer("You wrong!!!" + "\n" + "Answer correct" + " is " + arr[x], "practice-container", "wrong");
}
}
function createQuestion() {
// removeElements('practice-container');
arr = [];
for (var i = 0; i < 4; i++) {
if (modePractice == 3) {
arr.push(arrqq[rand(0, arrqq.length - 1)]);
}
else {
var s = quangdb.aWordStartWith(String.fromCharCode(rand(97, 122)))
arr.push(s);
console.log(s);
}
}
x = rand(0, 3);
arrqq.push(arr[x]);
addDivToContainer("Mean: " + quangdb.getMean(arr[x]) + " ?", "practice-container", "quesion");
addDivToContainer("A: " + arr[0], "practice-container", "choice");
addDivToContainer("B: " + arr[1], "practice-container", "choice");
addDivToContainer("C: " + arr[2], "practice-container", "choice");
addDivToContainer("D: " + arr[3], "practice-container", "choice");
}
function setTime() {
times = parseInt(window.prompt("How many times do you want to play?"));
}
function test() {
displayQuiz()
modePractice = 3;
resetPractice();
setTime();
createQuestion();
}
function challenge() {
displayQuiz()
count = 0;
modePractice = 2;
timesChallenge = 3;
window.alert("You can be wrong up to " + timesChallenge + " times");
createQuestion();
}
function learn() {
displayQuiz()
modePractice = 1;
resetPractice();
setTime();
createQuestion();
}
class PhraseGame {
constructor() {
this.container = document.getElementById('phrase-container');
this.aSetOfPhrase = [];
this.aPhrase = "";
this.times = 5;
this.index = 0;
this.indexSwap = [];
this.ansPhrase = [];
this.randPhrase = [];
this.initt();
}
initt() {
this.phrases = [
///Likes
[
"He, doesn't, like, paying, money,",
"She, likes, giving, gifts,",
"They, like, listening, to, music,",
"He, likes, playing, the, drums,",
"They, don't, like, maths,"
],
/// Compare
[
"Gorillas, are, stronger, than, monkeys,",
"The river, is, wider, than, the road,",
"The digger, is, noiser, than, the spade,",
"Computer games, are, more, interesting, than, homework,",
"Cats, are, safer, than, tigers,"
],
///Places
[
"In, a hair salon, you, can, get, a haircut,",
"At, a florist, you, can, buy, flowers,",
"In, a stadium, you, can, watch, sports,",
"In, a convenience, store, you, can buy, a newspaper,",
"At, a bus stop, you , can, catch, a bus,",
]
];
}
displayy() {
document.getElementById('box-practice').style.display = 'none';
var containerDiv = document.getElementById('container-div');
if (containerDiv.style.display === 'none') {
containerDiv.style.display = 'block';
this.getASetOfPhrase();
this.getAPhrase();
this.getPhraseToArr();
this.mixPhrase();
this.updatePhrase();
}
else {
this.container.innerHTML = '';
document.getElementById('result-message').textContent = '';
containerDiv.style.display = 'none';
this.index = 0;
}
}
getASetOfPhrase() {
var tmp = rand(0, 2);
console.log(tmp);
console.log(this.phrases[tmp]);
this.aSetOfPhrase = this.phrases[tmp];
}
getAPhrase() {
this.aPhrase = this.aSetOfPhrase[this.index];
this.index++;
}
getPhraseToArr() {
this.randPhrase = [];
this.ansPhrase = [];
var tmp = '';
for (let i = 0; i < this.aPhrase.length; i++) {
if (this.aPhrase[i] == ',') {
this.ansPhrase.push(tmp);
tmp = '';
} else {
tmp += this.aPhrase[i];
}
}
}
mixPhrase() {
this.randPhrase = this.ansPhrase.slice();
for (let i = this.randPhrase.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i));
[this.randPhrase[i], this.randPhrase[j]] = [this.randPhrase[j], this.randPhrase[i]];
}
}
swapp(i) {
this.indexSwap.push(i);
this.updatePhrase();
if (this.indexSwap.length == 2) {
setTimeout(() => {
[this.randPhrase[this.indexSwap[0]], this.randPhrase[this.indexSwap[1]]] = [this.randPhrase[this.indexSwap[1]], this.randPhrase[this.indexSwap[0]]];
this.indexSwap = [];
this.updatePhrase();
}, 100);
}
}
updatePhrase() {
this.container.innerHTML = '';
document.getElementById('result-message').textContent = '';
for (let i = 0; i < this.randPhrase.length; i++) {
var phraseBox = document.createElement('div');
phraseBox.classList.add('phrase-box');
phraseBox.textContent = this.randPhrase[i];
if (this.indexSwap.includes(i)) {
phraseBox.classList.add('selected');
}
this.container.appendChild(phraseBox);
phraseBox.addEventListener('click', () => this.swapp(i));
}
}
submitt() {
for (let i = 0; i < this.randPhrase.length; i++) {
if (this.randPhrase[i] !== this.ansPhrase[i]) {
document.getElementById('result-message').textContent = "Wrong!!!";
return;
}
}
document.getElementById('result-message').textContent = "Exactly!!!";
setTimeout(() => {
if (this.index == 5) {
window.alert("End game!");
this.displayy();
}
else {
this.getAPhrase();
this.getPhraseToArr();
this.mixPhrase();
this.updatePhrase();
}
}, 300);
}
}
/*
Đô có thể nhớ n từ vựng(random 25-30 từ), cho k tờ giấy A4(rand 5-7 tờ),
tờ thứ k1 có v1 từ rand(5 -7 từ) trong đó có x1 từ đúng(rand từ 1 - v1) \
tờ thứ k2 có v2 từ rand(5- 7 từ) trong đó có x2 từ đúng(rand từ 1 - v2)
Giúp Đô tìm số từ vựng nhiều nhất mà Đô có thể học sao cho số từ không vượt quá n.
*/