質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -137,3 +137,181 @@
|
|
137
137
|
</html>
|
138
138
|
|
139
139
|
```
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```JavaScript
|
144
|
+
|
145
|
+
const MAX_NUMBER = 75;
|
146
|
+
|
147
|
+
let main = document.getElementById('main');
|
148
|
+
|
149
|
+
let button = document.getElementById('btn');
|
150
|
+
|
151
|
+
let history = document.getElementById('history');
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
let historyArray = [];
|
160
|
+
|
161
|
+
let targetNumber = [];
|
162
|
+
|
163
|
+
for(let i = 1; i <= MAX_NUMBER; i++){
|
164
|
+
|
165
|
+
targetNumber.push(i);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
let timerId;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
button.onclick = () => {
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
if(targetNumber.length === 0){
|
180
|
+
|
181
|
+
alert('すべての番号の発表が終わりました') ;
|
182
|
+
|
183
|
+
clearInterval(timerId);
|
184
|
+
|
185
|
+
return;
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
if(button.textContent === 'スタート'){
|
192
|
+
|
193
|
+
button.textContent = 'ストップ';
|
194
|
+
|
195
|
+
timerId = setInterval( () => {
|
196
|
+
|
197
|
+
let targetIndex = Math.floor(Math.random() * targetNumber.length) ;
|
198
|
+
|
199
|
+
main.textContent = targetNumber[targetIndex];
|
200
|
+
|
201
|
+
}, 100)
|
202
|
+
|
203
|
+
}else{
|
204
|
+
|
205
|
+
button.textContent = 'スタート';
|
206
|
+
|
207
|
+
clearInterval(timerId);
|
208
|
+
|
209
|
+
let targetIndex = targetNumber.indexOf(Number(main.textContent));
|
210
|
+
|
211
|
+
targetNumber.splice(targetIndex, 1);
|
212
|
+
|
213
|
+
historyArray.push(main.textContent);
|
214
|
+
|
215
|
+
history.textContent = historyArray;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
$(function() {
|
222
|
+
|
223
|
+
$("td").click(function() {
|
224
|
+
|
225
|
+
// 現在のセルの色が無色透明かを判別
|
226
|
+
|
227
|
+
if($(this).css("background-color")=="rgba(0, 0, 0, 0)") {
|
228
|
+
|
229
|
+
// 赤色に染める
|
230
|
+
|
231
|
+
$(this).css("background-color", "red");
|
232
|
+
|
233
|
+
} else {
|
234
|
+
|
235
|
+
// 無色透明にする
|
236
|
+
|
237
|
+
$(this).css("background-color", "");
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
});
|
242
|
+
|
243
|
+
});
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
```
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
```CSS
|
252
|
+
|
253
|
+
body {
|
254
|
+
|
255
|
+
font-family: Arial, sans-serif;
|
256
|
+
|
257
|
+
text-align: center;
|
258
|
+
|
259
|
+
font-size: 16px;
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
#btn{
|
264
|
+
|
265
|
+
width: 200px;
|
266
|
+
|
267
|
+
height: 100px;
|
268
|
+
|
269
|
+
background: crimson;
|
270
|
+
|
271
|
+
border-radius: 50%;
|
272
|
+
|
273
|
+
margin: 30px auto;
|
274
|
+
|
275
|
+
text-align: center;
|
276
|
+
|
277
|
+
line-height: 100px;
|
278
|
+
|
279
|
+
font-weight: bold;
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
#container {
|
284
|
+
|
285
|
+
margin: 0 auto;
|
286
|
+
|
287
|
+
width: 322px;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
td,th {
|
292
|
+
|
293
|
+
width: 60px;
|
294
|
+
|
295
|
+
height: 45px;
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
td {
|
300
|
+
|
301
|
+
background-color: burlywood;
|
302
|
+
|
303
|
+
text-align: center;
|
304
|
+
|
305
|
+
border-radius: 50%;
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
th {
|
310
|
+
|
311
|
+
color: rgb(9, 255, 0);
|
312
|
+
|
313
|
+
font-size: 22px;
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
```
|