teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

修正

2020/07/02 10:08

投稿

begine
begine

スコア7

title CHANGED
File without changes
body CHANGED
@@ -21,7 +21,6 @@
21
21
 
22
22
 
23
23
  let currentNum = 0;
24
- let isAnswered;
25
24
  let score = 0;
26
25
 
27
26
 

2

修正

2020/07/02 10:08

投稿

begine
begine

スコア7

title CHANGED
File without changes
body CHANGED
@@ -18,87 +18,13 @@
18
18
  ### 該当のソースコード
19
19
 
20
20
  ```javascript
21
- document.addEventListener('DOMContentLoaded', function() { //画面表示したら以下を発火
22
- startTime = Date.now();
23
- countDown();
24
- });
25
21
 
26
- function countDown() {
27
- timerId = setTimeout (function() {
28
- //timerIdをsetTimeoutの返り値として取得 次の処理を指定したミリ秒後に実行(1度だけ)
29
22
 
30
- timeLeft = timeToCountDown - (Date.now() - startTime);
31
- //elapsedTimeは、1度しか使わないので直接代入した↑
32
-
33
- if(timeLeft < 0){ //残り時間が0より小さくなったらclearTimeoutを呼ぶ(タイマー停止)
34
- clearTimeout(timerId);
35
- timeLeft = 0; //timeLeftを0にして、updateTimerで更新する
36
- updateTimer(timeLeft);
37
-
38
- btn.classList.remove('disabled'); // Nextボタンのdisabledを解除する
39
- btn.textContent = '結果発表'; // Nextボタンの表示は「結果発表」にする
40
- currentNum = quizSet.length - 1; // 最終問題まで終わったとする
41
- isAnswered = true;
42
- return; //clearTimeout()したら次のcountDown()を呼び出したくないためreturnする
43
- }
44
-
45
- updateTimer(timeLeft); // 呼び出し(渡すミリ秒はtimerLeft)
46
- countDown(); //countDownを再帰的に呼び出したいため、ここで呼ぶ。
47
- }, 10);
48
- }
49
-
50
-
51
- sbtn.addEventListener('click', function() { //STARTボタンがクリックされたらタイマーON
52
- startTime = Date.now(); // 押したときの時刻を取得
53
- countDown(); /* カウントダウン機能は setTimeoutを使い再帰的に実行させるため countDown() という名前の別関数にする。*/
54
- });
55
-
56
23
  let currentNum = 0;
57
24
  let isAnswered;
58
25
  let score = 0;
59
26
 
60
27
 
61
- function checkAnswer(li) {
62
- if (isAnswered) {
63
- return;
64
- }
65
- isAnswered = true;
66
-
67
- if (li.textContent === quizSet[currentNum].c[0]) {
68
- li.classList.add('correct');    
69
- score++;
70
- } else {
71
- li.classList.add('wrong');   
72
- }
73
-
74
- btn.classList.remove('disabled');
75
- }
76
-
77
- function setQuiz() {
78
- isAnswered = false;
79
-
80
- question.textContent = quizSet[currentNum].q;
81
-
82
- while (choices.firstChild) {
83
- choices.removeChild(choices.firstChild);
84
- }
85
-
86
- const shuffledChoices = shuffle([...quizSet[currentNum].c]);
87
- shuffledChoices.forEach(choice => {
88
- const li = document.createElement('li');
89
- li.textContent = choice;
90
- li.addEventListener('click', () => {
91
- checkAnswer(li);
92
- if (currentNum === quizSet.length - 1) clearTimeout(timerId); // 最終問題に回答したらタイマー止める
93
- });
94
- choices.appendChild(li);
95
- });
96
-
97
- if (currentNum === quizSet.length - 1) {
98
- btn.textContent = '結果発表';
99
- }
100
- }
101
-
102
28
  setQuiz();
103
29
 
104
30
  btn.addEventListener('click', () => {

1

修正

2020/07/02 10:06

投稿

begine
begine

スコア7

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  前回、ここで(https://teratail.com/questions/274345=カウントが0になったら残りの問題全てを不正解にしたい)で質問をさせていただきました。
4
4
 
5
- そこで正答率を「正解の数/質問の数」で計算するというアドバイスをいただいたのでコードを書き直してみたのですが、全問正解しても正答率が100%になせん
5
+ そこで正答率を「正解の数/質問の数」で計算するというアドバイスをいただいたのでコードを書き直してみたのですが、全問正解しても正答率が50%になってしいます
6
6
 
7
7
  以下のようにコードを書きました。
8
8
  ```ここに言語を入力