質問編集履歴

3

メソッド名修正(.html -> .text)

2015/09/23 09:12

投稿

bannaka
bannaka

スコア13

test CHANGED
File without changes
test CHANGED
@@ -294,7 +294,7 @@
294
294
 
295
295
  //youNums = [$("#youNum1").html(), $("#youNum2").html(), $("#youNum3").html()];
296
296
 
297
- $("#message").html(youNums[0] + " " + youNums[1] + " " + youNums[2] + " を設定しました");
297
+ $("#message").text(youNums[0] + " " + youNums[1] + " " + youNums[2] + " を設定しました");
298
298
 
299
299
  progress = 10;
300
300
 

2

html追記

2015/09/23 09:12

投稿

bannaka
bannaka

スコア13

test CHANGED
File without changes
test CHANGED
@@ -46,6 +46,14 @@
46
46
 
47
47
  ```lang-html
48
48
 
49
+ <!--メッセージ部分-->
50
+
51
+ <div id="message">3桁の設定ナンバーを決定してください
52
+
53
+ </div>
54
+
55
+
56
+
49
57
  <!--ユーザのカード。設定した数字3桁を表示する-->
50
58
 
51
59
  <div id="youcard">

1

コード修正

2015/09/23 05:23

投稿

bannaka
bannaka

スコア13

test CHANGED
File without changes
test CHANGED
@@ -135,3 +135,167 @@
135
135
  });
136
136
 
137
137
  ```
138
+
139
+ ###修正したコード
140
+
141
+ ```lang-javascript
142
+
143
+ var youNums = []; //プレイヤーが設定した3桁数字の変数(配列)
144
+
145
+ var progress; //進行管理用の変数
146
+
147
+ //console.log(progress, youNums);
148
+
149
+
150
+
151
+ $(".onNum").on("click", function () { //数字0〜9をクリックした時
152
+
153
+ if (progress == undefined) { //変数progressがundefinedの場合
154
+
155
+ $("#youNum1").html(this.id); //youNum1にクリックした数字を表示
156
+
157
+ $(this).css("background", "#919191"); //クリックした数字をグレー色に変更
158
+
159
+ progress = 1; //変数progressに1を代入
160
+
161
+ youNums[0] = $("#youNum1").html();
162
+
163
+ //console.log(progress, youNums);
164
+
165
+
166
+
167
+ } else if (progress == 1) { //変数progressが1場合
168
+
169
+ if (equal_youNum(this.id) == true) return; //利用済みの数字の場合処理を中断
170
+
171
+ $("#youNum2").html(this.id);
172
+
173
+ $(this).css("background", "#919191");
174
+
175
+ progress = 2;
176
+
177
+ youNums[1] = $("#youNum2").html();
178
+
179
+ //console.log(progress, youNums);
180
+
181
+
182
+
183
+ } else if (progress == 2) {
184
+
185
+ if (equal_youNum(this.id) == true) return;
186
+
187
+ $("#youNum3").html(this.id);
188
+
189
+ $(this).css("background", "#919191");
190
+
191
+ $("#ok").css("background", "#da5758"); //OKボタンを赤色を変更
192
+
193
+ progress = 3;
194
+
195
+ youNums[2] = $("#youNum3").html();
196
+
197
+ //console.log(progress, youNums);
198
+
199
+
200
+
201
+ } else {
202
+
203
+ }
204
+
205
+ });
206
+
207
+
208
+
209
+ function equal_youNum(val) { //onNum1,onNum2の数字利用済み判定
210
+
211
+ if (val == $("#youNum1").html()) { //youNum1の数字と入力した数字がと一致するかのチェック
212
+
213
+ return true; //一致した場合true
214
+
215
+ } else if (val == $("#youNum2").html()) { //youNum2の数字と入力した数字がと一致するかのチェック
216
+
217
+ return true; //一致した場合true
218
+
219
+ } else {
220
+
221
+ return false; //いずれも一致しない場合false
222
+
223
+ }
224
+
225
+ }
226
+
227
+
228
+
229
+ $("#del").on("click", function () { //DELをクリックしたとき
230
+
231
+ if (progress == 3) { //進行管理が3の場合
232
+
233
+ $("#youNum3").empty(); //3桁目に表示していた数字を削除
234
+
235
+ $("#" + youNums[2]).css("background", "#fff"); //削除した数字の入力ボタンを白色に戻す
236
+
237
+ progress = 2; //変更管理を2に変更
238
+
239
+ youNums.splice(2); //プレイヤー設定番号の変数(配列)を削除
240
+
241
+ //console.log(progress, youNums);
242
+
243
+
244
+
245
+ } else if (progress == 2) {
246
+
247
+ $("#youNum2").empty();
248
+
249
+ $("#" + youNums[1]).css("background", "#fff");
250
+
251
+ progress = 1;
252
+
253
+ youNums.splice(1);
254
+
255
+ //console.log(progress, youNums);
256
+
257
+
258
+
259
+ } else if (progress == 1) {
260
+
261
+ $("#youNum1").empty();
262
+
263
+ $("#" + youNums[0]).css("background", "#fff");
264
+
265
+ progress = undefined;
266
+
267
+ youNums.splice(0);
268
+
269
+ //console.log(progress, youNums);
270
+
271
+
272
+
273
+ } else {
274
+
275
+
276
+
277
+ }
278
+
279
+ });
280
+
281
+
282
+
283
+ $("#ok").on("click", function () { //OKをクリックしたとき
284
+
285
+ if (progress == 3) { //変数progressが3の場合
286
+
287
+ //youNums = [$("#youNum1").html(), $("#youNum2").html(), $("#youNum3").html()];
288
+
289
+ $("#message").html(youNums[0] + " " + youNums[1] + " " + youNums[2] + " を設定しました");
290
+
291
+ progress = 10;
292
+
293
+ } else { //変数progressが3以外の場合
294
+
295
+ }
296
+
297
+ //console.log(progress, youNums);
298
+
299
+ });
300
+
301
+ ```