回答編集履歴
3
ソースコードの修正
test
CHANGED
@@ -28,9 +28,9 @@
|
|
28
28
|
|
29
29
|
var Fruits_price = ["250", "120", "450", "300", "780", "980", "350", "1280"];
|
30
30
|
|
31
|
-
|
31
|
+
var Fruits_size = 8;
|
32
32
|
|
33
|
-
|
33
|
+
|
34
34
|
|
35
35
|
|
36
36
|
|
@@ -46,9 +46,7 @@
|
|
46
46
|
|
47
47
|
console.log(input);
|
48
48
|
|
49
|
-
|
49
|
+
for (i = 0; i <= Fruits_size; i++) {
|
50
|
-
|
51
|
-
+ for (i = 0; i < Fruits_price.length ; i++) {
|
52
50
|
|
53
51
|
- if ((input = Fruits_name[i])) {
|
54
52
|
|
@@ -70,8 +68,124 @@
|
|
70
68
|
|
71
69
|
</html>
|
72
70
|
|
71
|
+
```
|
73
72
|
|
74
73
|
|
75
74
|
|
76
75
|
|
76
|
+
|
77
|
+
### もう少し修正するなら
|
78
|
+
|
79
|
+
データはオブジェクトか配列でまとめてしまったほうが後々使いやすいです。
|
80
|
+
|
77
81
|
```
|
82
|
+
|
83
|
+
<!DOCTYPE html>
|
84
|
+
|
85
|
+
<html>
|
86
|
+
|
87
|
+
<head>
|
88
|
+
|
89
|
+
<meta charset="UTF-8" />
|
90
|
+
|
91
|
+
<title>フルーツの値段</title>
|
92
|
+
|
93
|
+
</head>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<body>
|
98
|
+
|
99
|
+
<script>
|
100
|
+
|
101
|
+
var fruitsArray = [{
|
102
|
+
|
103
|
+
name: 'リンゴ',
|
104
|
+
|
105
|
+
price: '250'
|
106
|
+
|
107
|
+
}, {
|
108
|
+
|
109
|
+
name: 'オレンジ',
|
110
|
+
|
111
|
+
price: '120'
|
112
|
+
|
113
|
+
}, {
|
114
|
+
|
115
|
+
name: 'ブドウ',
|
116
|
+
|
117
|
+
price: '450'
|
118
|
+
|
119
|
+
}, {
|
120
|
+
|
121
|
+
name: 'バナナ',
|
122
|
+
|
123
|
+
price: '300'
|
124
|
+
|
125
|
+
}, {
|
126
|
+
|
127
|
+
name: 'メロン',
|
128
|
+
|
129
|
+
price: '780'
|
130
|
+
|
131
|
+
}, {
|
132
|
+
|
133
|
+
name: 'スイカ',
|
134
|
+
|
135
|
+
price: '980'
|
136
|
+
|
137
|
+
}, {
|
138
|
+
|
139
|
+
name: 'キウイ',
|
140
|
+
|
141
|
+
price: '350'
|
142
|
+
|
143
|
+
}, {
|
144
|
+
|
145
|
+
name: 'パイナップル',
|
146
|
+
|
147
|
+
price: '1280'
|
148
|
+
|
149
|
+
}]
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
var input = prompt("価値を調べたい果物の名前を入力してください");
|
156
|
+
|
157
|
+
var outMsg;
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
var i;
|
162
|
+
|
163
|
+
outMsg = "価格表に" + input + "は登録されていません";
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
for (i = 0; i < fruitsArray.length; i++) {
|
168
|
+
|
169
|
+
const fruits = fruitsArray[i]
|
170
|
+
|
171
|
+
if ((input == fruits.name)) {
|
172
|
+
|
173
|
+
outMsg = fruits.name + "の値段は" + fruits.price + "円です";
|
174
|
+
|
175
|
+
break;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
alert(outMsg);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
</script>
|
186
|
+
|
187
|
+
</body>
|
188
|
+
|
189
|
+
</html>
|
190
|
+
|
191
|
+
```
|
2
ソースコードの修正
test
CHANGED
File without changes
|
1
ソースコードの修正
test
CHANGED
@@ -28,7 +28,9 @@
|
|
28
28
|
|
29
29
|
var Fruits_price = ["250", "120", "450", "300", "780", "980", "350", "1280"];
|
30
30
|
|
31
|
-
var Fruits_size = 8;
|
31
|
+
- var Fruits_size = 8;
|
32
|
+
|
33
|
+
+ //var Fruits_size = 8;
|
32
34
|
|
33
35
|
|
34
36
|
|
@@ -44,7 +46,9 @@
|
|
44
46
|
|
45
47
|
console.log(input);
|
46
48
|
|
47
|
-
for (i = 0; i <= Fruits_size; i++) {
|
49
|
+
- for (i = 0; i <= Fruits_size; i++) {
|
50
|
+
|
51
|
+
+ for (i = 0; i < Fruits_price.length ; i++) {
|
48
52
|
|
49
53
|
- if ((input = Fruits_name[i])) {
|
50
54
|
|