質問編集履歴

4

質問文にラスト2行を追加しました。

2019/05/16 01:10

投稿

amaturePy
amaturePy

スコア131

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  私のコードで足りないところがあればご教授願いたいです。
6
6
 
7
+ また私としては54行目のansに値がないためにこの問題が起きていると考えています。→function関数でユーザーが選択した回答を取得→正解(answer)と照合→一致したなら+1点というロジックで対応。したつもりなのですが、うまく作動しません。ロジックや考え方など自体が間違っているようでしたらご教授願いたいです。
8
+
7
9
  <テーブル:quiz>
8
10
 
9
11
  <カラム:id/question/choice_1/choice_2/choice_3/answer>

3

labelタグのonclick関数とfunction choiceを追加しました。

2019/05/16 01:10

投稿

amaturePy
amaturePy

スコア131

test CHANGED
File without changes
test CHANGED
@@ -86,102 +86,126 @@
86
86
 
87
87
  ?>
88
88
 
89
+
90
+
89
- <h4> <?php echo $number . ".) " . $question; ?></h4>
91
+ <h4> <?php echo $number . ".) " . $question; ?></h4>
90
-
92
+
91
- <label><input type="radio" value="<?php echo $ans_array[0]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[0]; ?></label>
93
+ <label><input type="radio" oncick="choice" value="<?php echo $ans_array[0]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[0]; ?></label>
92
-
94
+
93
- <label><input type="radio" value="<?php echo $ans_array[1]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[1]; ?></label>
95
+ <label><input type="radio" onclick="choice" value="<?php echo $ans_array[1]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[1]; ?></label>
94
-
96
+
95
- <label><input type="radio" value="<?php echo $ans_array[2]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[2]; ?></label>
97
+ <label><input type="radio" onclick="choice" value="<?php echo $ans_array[2]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[2]; ?></label>
98
+
99
+
100
+
101
+ <?php
102
+
103
+ }
104
+
105
+ ?>
106
+
107
+
108
+
109
+ <br><br>
110
+
111
+
112
+
113
+ <button onclick="returnScore()">View Results</button>
114
+
115
+
116
+
117
+ <script> /////////////////////////////////////////////////////////////////////////////// Showing total score
118
+
119
+ var ans = [];
120
+
121
+ var answers = [];
122
+
123
+ answers[0]="Japanese";
124
+
125
+ answers[1]="Sushi";
126
+
127
+ answers[2]="Abe";
128
+
129
+ answers[3]="Yen";
130
+
131
+ answers[4]="JAL";
132
+
133
+ answers[5]="Tokyo";
134
+
135
+ answers[6]="Naruto";
136
+
137
+ answers[7]="Reiwa";
138
+
139
+ answers[8]="Line";
140
+
141
+ answers[9]="Kento";
142
+
143
+
144
+
145
+ function choice(){
146
+
147
+ if ans=$ans_array===answers;{
148
+
149
+ score+=1
150
+
151
+ }else{
152
+
153
+ score+=0;
154
+
155
+ }
156
+
157
+ return choice;
158
+
159
+ }
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+ function getScore(){
168
+
169
+ var score=0;
170
+
171
+ var numQuestion=10;
172
+
173
+ //return score ;
174
+
175
+ //return numQuestion ;
176
+
177
+ // }
178
+
179
+ // score = getScore();
180
+
181
+ for(var i=0;i<=numQuestion;i++) {
182
+
183
+ if(ans[i]==answers[i]) {
184
+
185
+ score+=1;
186
+
187
+ } else {
188
+
189
+ score+=0;
190
+
191
+ }
192
+
193
+ }
194
+
195
+ return score;//add
196
+
197
+ }
96
198
 
97
199
 
98
200
 
99
- <?php
201
+ function returnScore(){
202
+
203
+ console.log('test')
204
+
205
+ alert("Your Score is" + getScore()+"/10");
100
206
 
101
207
  }
102
208
 
103
- ?>
104
-
105
-
106
-
107
- <br><br>
108
-
109
-
110
-
111
- <button onclick="returnScore()">View Results</button>
112
-
113
-
114
-
115
- <script> ///////////////////////////////////////////////////////////////////// Showing total score
116
-
117
- var ans = [];
118
-
119
- var answers = [];
120
-
121
- answers[0]="Japanese";
122
-
123
- answers[1]="Sushi";
124
-
125
- answers[2]="Abe";
126
-
127
- answers[3]="Yen";
128
-
129
- answers[4]="JAL";
130
-
131
- answers[5]="Tokyo";
132
-
133
- answers[6]="Naruto";
134
-
135
- answers[7]="Reiwa";
136
-
137
- answers[8]="Line";
138
-
139
- answers[9]="Kento";
140
-
141
-
142
-
143
- function getScore(){
144
-
145
- var score=0;
146
-
147
- var numQuestion=10;
148
-
149
- //return score ;
150
-
151
- //return numQuestion ;
152
-
153
- // }
154
-
155
- // score = getScore();
156
-
157
- for(var i=0;i<=numQuestion;i++) {
158
-
159
- if(ans[i]==answers[i]) {
160
-
161
- score+=1;
162
-
163
- } else {
164
-
165
- score+=0;
166
-
167
- }
168
-
169
- }
170
-
171
- return score;//add
172
-
173
- }
174
-
175
-
176
-
177
- function returnScore(){
178
-
179
- console.log('test')
180
-
181
- alert("Your Score is" + getScore()+"/10");
182
-
183
- }
184
-
185
209
 
186
210
 
187
211
  </script>

2

formタグのgetメソッドを削除いたしました。

2019/05/16 01:09

投稿

amaturePy
amaturePy

スコア131

test CHANGED
File without changes
test CHANGED
@@ -86,11 +86,7 @@
86
86
 
87
87
  ?>
88
88
 
89
-
90
-
91
- <from action="" method="get">
92
-
93
- <h4> <?php echo $number . ".) " . $question; ?></h4>
89
+ <h4> <?php echo $number . ".) " . $question; ?></h4>
94
90
 
95
91
  <label><input type="radio" value="<?php echo $ans_array[0]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[0]; ?></label>
96
92
 
@@ -98,9 +94,7 @@
98
94
 
99
95
  <label><input type="radio" value="<?php echo $ans_array[2]; ?>" name="<?php echo $question; ?>"> <?php echo $ans_array[2]; ?></label>
100
96
 
101
- </from>
97
+
102
-
103
-
104
98
 
105
99
  <?php
106
100
 

1

DB情報を追加しました。

2019/05/14 02:26

投稿

amaturePy
amaturePy

スコア131

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  私のコードで足りないところがあればご教授願いたいです。
6
6
 
7
+ <テーブル:quiz>
8
+
9
+ <カラム:id/question/choice_1/choice_2/choice_3/answer>
10
+
7
11
 
8
12
 
9
13
  ```<!DOCTYPE html>