回答編集履歴

4

かんーそ

2019/12/15 00:02

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -458,8 +458,6 @@
458
458
 
459
459
  const products = {apple:120,orange:140,grape:160,peach:210};
460
460
 
461
- const coin = {coin10:10,coin50:50,coin100:100,coin500:500};
462
-
463
461
  $(".fruit").on("click",function() {
464
462
 
465
463
  price = products[$(this).attr("id")];
@@ -470,7 +468,7 @@
470
468
 
471
469
  $(".coin").on("click",function() {
472
470
 
473
- pay(coin[$(this).attr("id")]);
471
+ pay(Number($(this).attr("id").replace("coin","")));
474
472
 
475
473
  });
476
474
 

3

追記

2019/12/15 00:02

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -174,7 +174,7 @@
174
174
 
175
175
 
176
176
 
177
- <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256- CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
177
+ <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
178
178
 
179
179
  <script>
180
180
 

2

追記

2019/12/14 11:12

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -293,3 +293,231 @@
293
293
  ```
294
294
 
295
295
  [サンプル](https://cdpn.io/asuchi0819/debug/eYmdRRV/GnAnbOqNZpDA)
296
+
297
+
298
+
299
+ ### ちなみに簡素に書くと
300
+
301
+ ```HTML
302
+
303
+
304
+
305
+ <!DOCTYPE html>
306
+
307
+ <html>
308
+
309
+ <head>
310
+
311
+ <meta charset="utf-8">
312
+
313
+ <style>
314
+
315
+ .center-box { text-align: center; }
316
+
317
+ .large-text{ font-size: 2.0rem; }
318
+
319
+ body {
320
+
321
+ background-color: #EE0000;
322
+
323
+ text-align: center;
324
+
325
+ margin: 220px 290px 500px 260px;
326
+
327
+ font-size: 24px;
328
+
329
+ }
330
+
331
+ header {}
332
+
333
+ main {
334
+
335
+ position:relative;
336
+
337
+ text-align: center;
338
+
339
+ }
340
+
341
+ footer {
342
+
343
+ background-color: darkblue;
344
+
345
+ border-bottom:1px solid #444;
346
+
347
+ text-align: center;
348
+
349
+ color: #fff;
350
+
351
+ }
352
+
353
+ h1 { margin: 0; }
354
+
355
+ p {
356
+
357
+ font-size: 100%;
358
+
359
+ text-align: center;
360
+
361
+ border-bottom: 1px solid #fff;
362
+
363
+ height: 100px;
364
+
365
+ }
366
+
367
+ ul {
368
+
369
+ padding: 0;
370
+
371
+ border-top: 1px solid #000000;
372
+
373
+ display: table; /* 定義 */
374
+
375
+ table-layout: fixed;
376
+
377
+ width: 100%;
378
+
379
+ }
380
+
381
+ li {
382
+
383
+ list-style-type:none;
384
+
385
+ border: 1px solid #666;
386
+
387
+ background-color: #fff;
388
+
389
+ display: table-cell; /* 定義 */
390
+
391
+ cursor: pointer;
392
+
393
+ }
394
+
395
+ li:hover {
396
+
397
+ background: #0066CC;
398
+
399
+ color:#fff;
400
+
401
+ }
402
+
403
+ button {
404
+
405
+ text-align:center;
406
+
407
+ border-radius: 40px;
408
+
409
+ font-size:100%;
410
+
411
+ background-color: #CCCCCC;
412
+
413
+ height: 80px;
414
+
415
+ color: #fff;
416
+
417
+ }
418
+
419
+ </style>
420
+
421
+ </head>
422
+
423
+ <body>
424
+
425
+ <button class="fruit" id="apple">りんご</button>
426
+
427
+ <button class="fruit" id="orange">おれんじ</button>
428
+
429
+ <button class="fruit" id="grape">ぐれーぷ</button>
430
+
431
+ <button class="fruit" id="peach">もも</button>
432
+
433
+ <button class="coin" id="coin10">10円</button>
434
+
435
+ <button class="coin" id="coin50">50円</button>
436
+
437
+ <button class="coin" id="coin100">100円</button>
438
+
439
+ <button class="coin" id="coin500">500円</button>
440
+
441
+ <div id="result-div" class="large-text"></div>
442
+
443
+ <div style="width:500px; height:250px; background:#0099cc;"></div>
444
+
445
+
446
+
447
+ <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
448
+
449
+ <script>
450
+
451
+ $(function(){
452
+
453
+ "use strict";
454
+
455
+ let total = 0;
456
+
457
+ let price = false;
458
+
459
+ const products = {apple:120,orange:140,grape:160,peach:210};
460
+
461
+ const coin = {coin10:10,coin50:50,coin100:100,coin500:500};
462
+
463
+ $(".fruit").on("click",function() {
464
+
465
+ price = products[$(this).attr("id")];
466
+
467
+ showprice(price);
468
+
469
+ });
470
+
471
+ $(".coin").on("click",function() {
472
+
473
+ pay(coin[$(this).attr("id")]);
474
+
475
+ });
476
+
477
+
478
+
479
+ function pay(amount){
480
+
481
+ total += amount;
482
+
483
+ if (price == false){
484
+
485
+ total = 0;
486
+
487
+ $("#result-div").html("商品を選んでね");
488
+
489
+ return;
490
+
491
+ } else if (total >= price){
492
+
493
+ $("#result-div").html("ありがとう~おつりは"+(total -price)+"円です。");
494
+
495
+ total = 0;
496
+
497
+ price = false;
498
+
499
+ }else{
500
+
501
+ $("#result-div").html("投入金額"+total);
502
+
503
+ }
504
+
505
+ }
506
+
507
+ function showprice (price) {
508
+
509
+ $("#result-div").html(price+"円投入してください。")
510
+
511
+ }
512
+
513
+ });
514
+
515
+ </script>
516
+
517
+ </body>
518
+
519
+ </html>
520
+
521
+
522
+
523
+ ```

1

追記

2019/12/14 11:10

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -180,7 +180,9 @@
180
180
 
181
181
  $(function(){
182
182
 
183
- "use strict"let total = 0;
183
+ "use strict";
184
+
185
+ let total = 0;
184
186
 
185
187
  let price = false;
186
188