-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
273 lines (260 loc) · 8.41 KB
/
script.js
File metadata and controls
273 lines (260 loc) · 8.41 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
var numSquares = 6; // number of squares
var colors = []; // array of random colors
var words = []; // array of random English words
var terms = {
Zhejiang: '浙江',
'to kill': '杀',
'incident, event': '事件',
'all circles, all walks of life': '各界',
'introspection, self-examination': '反思',
'unable, incapable': '无法',
'endure, bear': '忍受',
'heavy, weighty': '沉重',
"one's own (children, parents)": '亲生',
tragedy: '悲剧',
province: '省',
'profound, deep': '深刻',
'Jinhua City': '金华市',
'to be born': '出生',
'ordinary, common': '普通',
'labor worker': '工人',
food: '食品',
'workers and staff members': '职工',
'long-term; over a long period of time': '长期',
'place other than where one is; other places': '外地',
'train station': '火车站',
"since one's childhood": '从小到大',
'basically, on the whole': '基本上',
'look after, care for': '照顾',
'grow; grow up': '长大',
knit: '织',
sweater: '毛衣',
'support (financially); supply': '供',
'attend school; read; study': '读书',
'middle school, junior high school': '初中',
'go up to a higher level in school': '升',
'enter a school by passing the entrance exam': '考进',
'honors class; advanced class; tracked class for bright students': '重点班',
'first half (of a game, concert, period, etc.)': '上半',
'rank as; be ranked as': '排名',
'count from the end; count backwards': '倒数',
'second half': '下半',
'to be overjoyed (at an unexpected gain or good news)': '喜出望外',
midterm: '其中',
'the end of the semester': '期末',
'to bury': '埋下',
seed: '种子',
'end of the month': '月底',
'attend (meeting, discussion, etc.)': '参加',
'have learned of': '得知',
ferociously: '狠狠',
'to hit, to beat': '打',
'measure word for meals, occurrences, etc.': '顿',
'to kick': '踢',
soccer: '足球',
'to break': '打断',
'heavy pressure': '重压',
'under...': '之下',
'to feel': '感到',
'subject subject to discipline; control (a child)': '管',
'strict, stern': '严',
'realize, achieve, bring about': '实现',
'put forward, pose, raise': '提出',
'objective, target': '目标',
'profoundly; deeply': '深深',
'feel wronged': '委屈',
'repressed; depressed': '压抑',
'to remind': '提醒',
'once again; for the second time': '再次',
conflict: '冲突',
'hopelessness; despair; give up all hope': '绝望',
'gate; doorway; entrance; door': '门口儿',
'meausre word for things with handles or things to take hold of': '把',
'a hammer with a wood shaft': '木柄榔头',
'to; towards': '朝',
'back of head': '后脑',
smash: '砸',
'while still alive': '活活',
'to shock; to astonish': '震惊',
'to attend school': '就读',
'report; make known': '反映',
'ordinarily; normally': '平时',
'always, all the time': '一向',
'hardworking, painstaking': '刻苦',
frugal: '节俭',
'(of a student) of good character and scholarship': '品学兼优',
'character; nature; disposition': '性格',
'gentle and quiet': '文静',
'学习好,身体好,思想好的学生 - students who are good in studying, sports, and thinking': '三好学生',
'be admitted to the Communist Youth League': '入团',
'collective, group': '集体',
'enthusiastic, zealous': '热心',
'willing to help others': '乐于助人',
do: '干',
'violent conduct; atrocities': '暴行',
local: '当地',
'related; concerned; relevant': '有关',
expert: '专家',
"to hope that one's son will become a dragon; to hope that one's son will become successful": '望子成龙',
'eager, anxious (should be preceded by verb such as 成功 or 结婚)': '--心切',
children: '子女',
fragile: '脆弱',
'to lack': '缺乏',
legality: '法制',
'to lead to, give rise to': '导致',
'measure word for dramatic pieces': '出',
contradiction: '矛盾',
'be well trained': '训练有素',
'remove the corpse and erase all trace': '移尸灭迹',
'a brief note': '字条',
'to deceive, cheat, dupe': '欺骗',
'to see a doctor': '看病',
'surprisingly; unexpectedly': '居然',
'(do something) as usual': '照常',
'extremely; very': '十分',
'only; alone': '仅仅',
"school work; one's study": '学业',
'and; also; besides; moreover': '并且',
'to be indifferent': '淡薄',
'bear; sustain': '承受',
'hope; expectation': '期望',
'perfect; desirable; ideal': '理想',
'be bound to; inevitable': '必然',
'homicide; murder': '凶杀',
pornography: '色情',
'reading material': '读物',
'spread far and wide; spread unchecked': '泛滥',
'harmful; unwholesome': '不良',
'enhance; reinforce': '加强',
'moral integrity': '人格'
};
// get all the elements
// engDisplay new word button mode button squares message
var pickedColor;
var pickedWord;
var engDisplay = document.getElementById('engDisplay');
var messageDisplay = document.getElementById('message');
var resetButton = document.querySelector('#reset');
var squares = document.querySelectorAll('.square');
var modeButtons = document.querySelectorAll('.mode');
var h1 = document.querySelector('h1');
var pre = document.querySelector('#pre');
var post = document.querySelector('#post');
var eDisplay;
init();
function init() {
setupModeButtons(); // setup mode buttons
setupSquares(); // sets up square colors
reset(); // generate random colors
}
// sets up buttons and determines how many squares to show
function setupModeButtons() {
for (var i = 0; i < modeButtons.length; i++) {
modeButtons[i].addEventListener('click', function() {
// removes class from both
modeButtons[0].classList.remove('selected');
modeButtons[1].classList.remove('selected');
this.classList.add('selected');
// how many squares do we show
this.textContent === 'Easy' ? (numSquares = 3) : (numSquares = 6);
reset();
});
}
}
function setupSquares() {
for (var i = 0; i < squares.length; i++) {
squares[i].addEventListener('click', function() {
var clickedColor = this.style.backgroundColor;
if (this.textContent === terms[pickedWord]) {
messageDisplay.textContent = 'Correct!';
changeColorsAndText(clickedColor, this.textContent);
h1.style.backgroundColor = clickedColor;
resetButton.textContent = 'Play again?';
pre.textContent = eDisplay + ' is';
engDisplay.textContent = terms[pickedWord];
post.textContent = 'in Chinese';
} else {
messageDisplay.textContent = 'Try again.';
this.style.backgroundColor = '#232323';
this.textContent = '';
}
});
}
}
function reset() {
// generate random colors
colors = generateRandomColors(numSquares);
// generate random words
words = generateRandomWords(numSquares);
// pick a random color
pickedColor = pickColor();
// pick a random word
pickedWord = pickWord();
engDisplay.textContent = pickedWord; // will implement later using Python
eDisplay = engDisplay.textContent;
resetButton.textContent = 'New Word';
// change colors of squares
for (var i = 0; i < squares.length; i++) {
if (colors[i] && words[i]) {
console.log('hi');
squares[i].style.display = 'inline-block';
squares[i].style.backgroundColor = colors[i];
squares[i].textContent = terms[words[i]];
} else {
squares[i].style.display = 'none';
}
}
h1.style.backgroundColor = 'steelblue';
pre.textContent = 'What is';
post.textContent = 'in Chinese?';
messageDisplay.textContent = '';
}
resetButton.addEventListener('click', function() {
reset();
});
function changeColorsAndText(color, text) {
for (var i = 0; i < squares.length; i++) {
squares[i].style.background = color;
squares[i].textContent = text;
}
}
function pickColor() {
var random = Math.floor(Math.random() * colors.length);
return colors[random];
}
function pickWord() {
var random = Math.floor(Math.random() * words.length);
return words[random];
}
function generateRandomColors(num) {
var arr = [];
for (var i = 0; i < num; i++) {
arr.push(randomColor());
}
return arr;
}
function generateRandomWords(num) {
var arr = [];
for (var i = 0; i < num; i++) {
r = randomWord();
while (arr.includes(r)) {
r = randomWord();
}
arr.push(r);
}
return arr;
}
function randomColor() {
// pick a "red" from 0-255
var r = Math.floor(Math.random() * 180);
// pick a "green" from 0-255
var g = Math.floor(Math.random() * 180);
// pick a "blue" from 0-255
var b = Math.floor(Math.random() * 180);
// spaces are CRUCIAL
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
}
function randomWord() {
var keys = Object.keys(terms);
return keys[Math.floor(keys.length * Math.random())];
}