回答編集履歴
5
追記
test
CHANGED
@@ -37,3 +37,397 @@
|
|
37
37
|
window.setTimeout(function(){document.getElementById("choices").style.display ="none";},2000);
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
### 追記
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
質問内容からずれますがこんなのはどうでしょうか?
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```HTML
|
52
|
+
|
53
|
+
<html lang="ja">
|
54
|
+
|
55
|
+
<head>
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
<meta charset="utf-8">
|
60
|
+
|
61
|
+
<title>Quiz</title>
|
62
|
+
|
63
|
+
<link rel="stylesheet" href="css/styles.css">
|
64
|
+
|
65
|
+
</head>
|
66
|
+
|
67
|
+
<body>
|
68
|
+
|
69
|
+
<div class="container">
|
70
|
+
|
71
|
+
<p id="question"></p>
|
72
|
+
|
73
|
+
<ul id="choices"></ul>
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<section id="result">
|
78
|
+
|
79
|
+
<p></p>
|
80
|
+
|
81
|
+
<a href="">Replay?</a>
|
82
|
+
|
83
|
+
</section>
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<script src="js/main.js"></script>
|
90
|
+
|
91
|
+
</body>
|
92
|
+
|
93
|
+
</html>
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
```CSS
|
98
|
+
|
99
|
+
body {
|
100
|
+
|
101
|
+
background: #efdec1;
|
102
|
+
|
103
|
+
font-size: 14px;
|
104
|
+
|
105
|
+
font-family: Verdana, sans-serif;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
.container {
|
112
|
+
|
113
|
+
width: 400px;
|
114
|
+
|
115
|
+
margin: 8px auto;
|
116
|
+
|
117
|
+
background: #fff;
|
118
|
+
|
119
|
+
border-radius: 4px;
|
120
|
+
|
121
|
+
padding: 16px;
|
122
|
+
|
123
|
+
position: relative;
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
#question {
|
130
|
+
|
131
|
+
margin-bottom: 16px;
|
132
|
+
|
133
|
+
font-weight: bold;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
#choices {
|
140
|
+
|
141
|
+
list-style: none;
|
142
|
+
|
143
|
+
padding: 0;
|
144
|
+
|
145
|
+
margin-bottom: 16px;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
#choices > li {
|
152
|
+
|
153
|
+
border: 1px solid #ccc;
|
154
|
+
|
155
|
+
border-radius: 4px;
|
156
|
+
|
157
|
+
padding: 10px;
|
158
|
+
|
159
|
+
margin-bottom: 10px;
|
160
|
+
|
161
|
+
cursor: pointer;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
#choices > li:hover {
|
168
|
+
|
169
|
+
background: #f8f8f8;
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
#choices > li.correct {
|
176
|
+
|
177
|
+
background: #d4edda;
|
178
|
+
|
179
|
+
border-color: #c3e6cb;
|
180
|
+
|
181
|
+
color: #155724;
|
182
|
+
|
183
|
+
font-weight: bold;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
#choices > li.correct::after {
|
190
|
+
|
191
|
+
content: " ... correct!";
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
#choices > li.wrong {
|
198
|
+
|
199
|
+
background: #f8d8da;
|
200
|
+
|
201
|
+
border-color: #f5c6cb;
|
202
|
+
|
203
|
+
color: #721c24;
|
204
|
+
|
205
|
+
font-weight: bold;
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
#choices > li.wrong::after {
|
212
|
+
|
213
|
+
content: " ... wrong!";
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
#result > a {
|
220
|
+
|
221
|
+
background: #3498db;
|
222
|
+
|
223
|
+
padding: 8px;
|
224
|
+
|
225
|
+
border-radius: 4px;
|
226
|
+
|
227
|
+
cursor: pointer;
|
228
|
+
|
229
|
+
text-align: center;
|
230
|
+
|
231
|
+
color: #fff;
|
232
|
+
|
233
|
+
box-shadow: 0 4px 0 #2880b9;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
#result {
|
240
|
+
|
241
|
+
position: absolute;
|
242
|
+
|
243
|
+
width: 300px;
|
244
|
+
|
245
|
+
background: #fff;
|
246
|
+
|
247
|
+
padding: 30px;
|
248
|
+
|
249
|
+
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
|
250
|
+
|
251
|
+
/* top: 50px; */
|
252
|
+
|
253
|
+
top: -500px;
|
254
|
+
|
255
|
+
left: 0;
|
256
|
+
|
257
|
+
right: 0;
|
258
|
+
|
259
|
+
margin: 0 auto;
|
260
|
+
|
261
|
+
border-radius: 3px;
|
262
|
+
|
263
|
+
text-align: center;
|
264
|
+
|
265
|
+
transition: 0.4s ease-out;
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
#result.show {
|
272
|
+
|
273
|
+
top: 50px;
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
#result > p {
|
280
|
+
|
281
|
+
font-size: 24px;
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
#result > a {
|
288
|
+
|
289
|
+
display: block;
|
290
|
+
|
291
|
+
text-decoration: none;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
```
|
296
|
+
|
297
|
+
```JS
|
298
|
+
|
299
|
+
'use strict';
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
{
|
304
|
+
|
305
|
+
const question = document.getElementById('question');
|
306
|
+
|
307
|
+
const choices = document.getElementById('choices');
|
308
|
+
|
309
|
+
const result = document.getElementById('result');
|
310
|
+
|
311
|
+
const scoreLabel = document.querySelector('#result > p');
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
const quizSet = [
|
316
|
+
|
317
|
+
// {q: 'What is A?', c: ['A0', 'A1', 'A2']},
|
318
|
+
|
319
|
+
// {q: 'What is B?', c: ['B0', 'B1', 'B2']},
|
320
|
+
|
321
|
+
// {q: 'What is C?', c: ['C0', 'C1', 'C2']},
|
322
|
+
|
323
|
+
{q: '世界で一番大きな湖は?', c: ['カスピ海', 'カリブ海', '琵琶湖']},
|
324
|
+
|
325
|
+
{q: '2の8乗は?', c: ['256', '64', '1024']},
|
326
|
+
|
327
|
+
{q: 'いま、何問目?', c: ['3問目', '4問目', '5問目']},
|
328
|
+
|
329
|
+
];
|
330
|
+
|
331
|
+
let currentNum = 0;
|
332
|
+
|
333
|
+
let isAnswered;
|
334
|
+
|
335
|
+
let score = 0;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
function shuffle(arr) {
|
340
|
+
|
341
|
+
for (let i = arr.length - 1; i > 0; i--) {
|
342
|
+
|
343
|
+
const j = Math.floor(Math.random() * (i + 1));
|
344
|
+
|
345
|
+
[arr[j], arr[i]] = [arr[i], arr[j]];
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
return arr;
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
function checkAnswer(li) {
|
356
|
+
|
357
|
+
if (isAnswered) {
|
358
|
+
|
359
|
+
return;
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
isAnswered = true;
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
if (li.textContent === quizSet[currentNum].c[0]) {
|
368
|
+
|
369
|
+
li.classList.add('correct');
|
370
|
+
|
371
|
+
score++;
|
372
|
+
|
373
|
+
} else {
|
374
|
+
|
375
|
+
li.classList.add('wrong');
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
}
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
function setQuiz() {
|
386
|
+
|
387
|
+
isAnswered = false;
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
question.textContent = quizSet[currentNum].q;
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
while (choices.firstChild) {
|
396
|
+
|
397
|
+
choices.removeChild(choices.firstChild);
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
const shuffledChoices = shuffle([...quizSet[currentNum].c]);
|
404
|
+
|
405
|
+
shuffledChoices.forEach(choice => {
|
406
|
+
|
407
|
+
const li = document.createElement('li');
|
408
|
+
|
409
|
+
li.textContent = choice;
|
410
|
+
|
411
|
+
li.addEventListener('click', () => {
|
412
|
+
|
413
|
+
checkAnswer(li);
|
414
|
+
|
415
|
+
});
|
416
|
+
|
417
|
+
choices.appendChild(li);
|
418
|
+
|
419
|
+
});
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
setQuiz();
|
426
|
+
|
427
|
+
window.setTimeout(function(){currentNum++;setQuiz();window.setTimeout(function(){currentNum++;setQuiz();window.setTimeout(function(){scoreLabel.textContent=`Score: ${score} / ${quizSet.length}`;result.classList.add('show');},5000);},5000);},5000);
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
```
|
432
|
+
|
433
|
+
[サンプル](https://s.codepen.io/asuchi0819/debug/VwZQbMV/XBkGRqgpjLZA)
|
4
追記
test
CHANGED
@@ -27,3 +27,13 @@
|
|
27
27
|
window.setTimeout("newi()", 10000);
|
28
28
|
|
29
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
「関数の定義ができないならしなければいいじゃない」(某漫画をオマージュ)
|
34
|
+
|
35
|
+
```JS
|
36
|
+
|
37
|
+
window.setTimeout(function(){document.getElementById("choices").style.display ="none";},2000);
|
38
|
+
|
39
|
+
```
|
3
失敬
test
CHANGED
@@ -24,6 +24,6 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
setTimeout("newi()", 10000);
|
27
|
+
window.setTimeout("newi()", 10000);
|
28
28
|
|
29
29
|
```
|
2
こんなとこか?
test
CHANGED
@@ -3,3 +3,27 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
一定時間後JavaScriptで要素を非表示にしたりして操作できなくする。(本格的なものを作りたいなら不十分)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```HTML
|
10
|
+
|
11
|
+
<ul id="choices"></ul>
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
を非表示にしたいなら
|
16
|
+
|
17
|
+
```JavaScript
|
18
|
+
|
19
|
+
function newi(){
|
20
|
+
|
21
|
+
document.getElementById("choices").style.display ="none";
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
setTimeout("newi()", 10000);
|
28
|
+
|
29
|
+
```
|
1
追記
test
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
JavaScriptで要素を非表示にしたりして操作できなくする。(本格的なものを作りたいなら不十分)
|
5
|
+
一定時間後JavaScriptで要素を非表示にしたりして操作できなくする。(本格的なものを作りたいなら不十分)
|