回答編集履歴
1
answer
CHANGED
|
@@ -15,4 +15,32 @@
|
|
|
15
15
|
checkValue = answer1.item(i).value;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
```
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
〈加筆〉
|
|
21
|
+
jQueryを使っているようなので、もっとコードをシンプルにできます。
|
|
22
|
+
全体のスコア判定のイメージでサンプルを示します。
|
|
23
|
+
下記のコードのanswer1ってのは、ラジオボタンにつけるnameであることに注意です。
|
|
24
|
+
[:radio Selector | jQuery API Documentation](https://api.jquery.com/radio-selector/)
|
|
25
|
+
問題ごとにnameを変える必要があります。
|
|
26
|
+
```JavaScript
|
|
27
|
+
if ($('input:radio[name="answer1"]:checked').val() === '正解の値とか') {
|
|
28
|
+
score++;
|
|
29
|
+
}
|
|
30
|
+
if ($('input:radio[name="answer2"]:checked').val() === '正解の値とか') {
|
|
31
|
+
score++;
|
|
32
|
+
}
|
|
33
|
+
if ($('input:radio[name="answer3"]:checked').val() === '正解の値とか') {
|
|
34
|
+
score++;
|
|
35
|
+
}
|
|
36
|
+
if (score === 3) {
|
|
37
|
+
alert('全問正解');
|
|
38
|
+
}
|
|
39
|
+
else if (score > 0) {
|
|
40
|
+
alert(score + '問正解、惜しい');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
alert('不正解');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
```
|