質問編集履歴

3

修正

2020/07/02 10:08

投稿

begine
begine

スコア7

test CHANGED
File without changes
test CHANGED
@@ -43,8 +43,6 @@
43
43
 
44
44
 
45
45
  let currentNum = 0;
46
-
47
- let isAnswered;
48
46
 
49
47
  let score = 0;
50
48
 

2

修正

2020/07/02 10:08

投稿

begine
begine

スコア7

test CHANGED
File without changes
test CHANGED
@@ -38,73 +38,7 @@
38
38
 
39
39
  ```javascript
40
40
 
41
- document.addEventListener('DOMContentLoaded', function() { //画面表示したら以下を発火
42
41
 
43
- startTime = Date.now();
44
-
45
- countDown();
46
-
47
- });
48
-
49
-
50
-
51
- function countDown() {
52
-
53
- timerId = setTimeout (function() {
54
-
55
- //timerIdをsetTimeoutの返り値として取得 次の処理を指定したミリ秒後に実行(1度だけ)
56
-
57
-
58
-
59
- timeLeft = timeToCountDown - (Date.now() - startTime);
60
-
61
- //elapsedTimeは、1度しか使わないので直接代入した↑
62
-
63
-
64
-
65
- if(timeLeft < 0){ //残り時間が0より小さくなったらclearTimeoutを呼ぶ(タイマー停止)
66
-
67
- clearTimeout(timerId);
68
-
69
- timeLeft = 0; //timeLeftを0にして、updateTimerで更新する
70
-
71
- updateTimer(timeLeft);
72
-
73
-
74
-
75
- btn.classList.remove('disabled'); // Nextボタンのdisabledを解除する
76
-
77
- btn.textContent = '結果発表'; // Nextボタンの表示は「結果発表」にする
78
-
79
- currentNum = quizSet.length - 1; // 最終問題まで終わったとする
80
-
81
- isAnswered = true;
82
-
83
- return; //clearTimeout()したら次のcountDown()を呼び出したくないためreturnする
84
-
85
- }
86
-
87
-
88
-
89
- updateTimer(timeLeft); // 呼び出し(渡すミリ秒はtimerLeft)
90
-
91
- countDown(); //countDownを再帰的に呼び出したいため、ここで呼ぶ。
92
-
93
- }, 10);
94
-
95
- }
96
-
97
-
98
-
99
-
100
-
101
- sbtn.addEventListener('click', function() { //STARTボタンがクリックされたらタイマーON
102
-
103
- startTime = Date.now(); // 押したときの時刻を取得
104
-
105
- countDown(); /* カウントダウン機能は setTimeoutを使い再帰的に実行させるため countDown() という名前の別関数にする。*/
106
-
107
- });
108
42
 
109
43
 
110
44
 
@@ -115,88 +49,6 @@
115
49
  let score = 0;
116
50
 
117
51
 
118
-
119
-
120
-
121
- function checkAnswer(li) {
122
-
123
- if (isAnswered) {
124
-
125
- return;
126
-
127
- }
128
-
129
- isAnswered = true;
130
-
131
-
132
-
133
- if (li.textContent === quizSet[currentNum].c[0]) {
134
-
135
- li.classList.add('correct');    
136
-
137
- score++;
138
-
139
- } else {
140
-
141
- li.classList.add('wrong');   
142
-
143
- }
144
-
145
-
146
-
147
- btn.classList.remove('disabled');
148
-
149
- }
150
-
151
-
152
-
153
- function setQuiz() {
154
-
155
- isAnswered = false;
156
-
157
-
158
-
159
- question.textContent = quizSet[currentNum].q;
160
-
161
-
162
-
163
- while (choices.firstChild) {
164
-
165
- choices.removeChild(choices.firstChild);
166
-
167
- }
168
-
169
-
170
-
171
- const shuffledChoices = shuffle([...quizSet[currentNum].c]);
172
-
173
- shuffledChoices.forEach(choice => {
174
-
175
- const li = document.createElement('li');
176
-
177
- li.textContent = choice;
178
-
179
- li.addEventListener('click', () => {
180
-
181
- checkAnswer(li);
182
-
183
- if (currentNum === quizSet.length - 1) clearTimeout(timerId); // 最終問題に回答したらタイマー止める
184
-
185
- });
186
-
187
- choices.appendChild(li);
188
-
189
- });
190
-
191
-
192
-
193
- if (currentNum === quizSet.length - 1) {
194
-
195
- btn.textContent = '結果発表';
196
-
197
- }
198
-
199
- }
200
52
 
201
53
 
202
54
 

1

修正

2020/07/02 10:06

投稿

begine
begine

スコア7

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- そこで正答率を「正解の数/質問の数」で計算するというアドバイスをいただいたのでコードを書き直してみたのですが、全問正解しても正答率が100%になせん
9
+ そこで正答率を「正解の数/質問の数」で計算するというアドバイスをいただいたのでコードを書き直してみたのですが、全問正解しても正答率が50%になってしいます
10
10
 
11
11
 
12
12