質問編集履歴

1

コード修正

2019/06/02 21:33

投稿

0xy3225132r5w2k
0xy3225132r5w2k

スコア10

test CHANGED
File without changes
test CHANGED
@@ -52,40 +52,52 @@
52
52
 
53
53
  $('#search').click(function() {
54
54
 
55
- const money = $('.main-top__content--money').val();
55
+ let money = $('.main-top__content--money').val();
56
56
 
57
- const style = $('.main-top__content--style').val();
57
+ let style = $('.main-top__content--style').val();
58
58
 
59
59
 
60
60
 
61
- if(money==1 && style==1) {
62
-
63
- const nonce = Math.floor(Math.random()*tops.length);
64
-
65
- const name = tops[nonce].name;
61
+ let totalprice = 0;
66
-
67
- const price = tops[nonce].price;
68
62
 
69
63
 
70
64
 
71
- for (let totalprice = price; totalprice < 3000; totalprice += price) {
65
+
72
66
 
73
-
67
+ console.log(money);
74
68
 
75
- console.log(name);
69
+ $('#result').empty();
76
70
 
77
- }
78
71
 
79
-
80
72
 
81
- }
73
+ do {
74
+
75
+ let nonce = Math.floor(Math.random()*tops.length);
76
+
77
+ let name = tops[nonce].name;
78
+
79
+ let price = tops[nonce].price;
80
+
81
+
82
+
83
+ totalprice += price;
84
+
85
+
86
+
87
+ $('#result').append("商品名"+ "&nbsp"+ name + "&nbsp" +price + "円" + "<br>");
88
+
89
+ $('#totalPrice').append("合計金額"+ totalprice + "円");
90
+
91
+ // append(); 要素の追加
92
+
93
+ } while (totalprice <= money );
94
+
95
+
82
96
 
83
97
 
84
98
 
85
99
  });
86
100
 
87
-
88
-
89
101
  });
90
102
 
91
103
  ```