質問編集履歴
2
エラー内容の追記。
test
CHANGED
File without changes
|
test
CHANGED
@@ -220,4 +220,22 @@
|
|
220
220
|
|
221
221
|
自分で実装したが、35行目でエラ―発生。
|
222
222
|
|
223
|
+
エラー内容は以下の通り。
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
```ReferenceError: isInteger is not defined at eval (eval at <anonymous> (file:///C:/Users/1205d/Documents/JAVASCRIPTBAISICS/index.html:17:22), <anonymous>:1:1) at HTMLButtonElement.<anonymous> (file:///C:/Users/1205d/Documents/JAVASCRIPTBAISICS/index.html:34:22)
|
228
|
+
|
229
|
+
message: "isInteger is not defined"
|
230
|
+
|
231
|
+
stack: "ReferenceError: isInteger is not defined↵ at eval (eval at <anonymous> (file:///C:/Users/1205d/Documents/JAVASCRIPTBAISICS/index.html:17:22), <anonymous>:1:1)↵ at HTMLButtonElement.<anonymous> (file:///C:/Users/1205d/Documents/JAVASCRIPTBAISICS/index.html:34:22)"
|
232
|
+
|
233
|
+
__proto__: Error
|
234
|
+
|
235
|
+
コード
|
236
|
+
|
237
|
+
```
|
238
|
+
|
239
|
+
|
240
|
+
|
223
241
|
35行目→ p.textContent = (isInteger.parseFloat("Fizz") + " " + number);
|
1
実装したコードを掲載しました。よろしくお願いします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,15 +70,27 @@
|
|
70
70
|
|
71
71
|
if(number % fizzNum === 0 && number % buzzNum === 0 ) {
|
72
72
|
|
73
|
+
const p = document.createElement('p');
|
74
|
+
|
73
|
-
|
75
|
+
p.textContent = ("FizzBuzz" + " "+ number);
|
76
|
+
|
77
|
+
document.body.appendChild(p);
|
74
78
|
|
75
79
|
} else if(number % fizzNum === 0) {
|
76
80
|
|
81
|
+
const p = document.createElement('p');
|
82
|
+
|
77
|
-
|
83
|
+
p.textContent = ("Fizz" + " " + number);
|
84
|
+
|
85
|
+
document.body.appendChild(p);
|
78
86
|
|
79
87
|
} else if(number % buzzNum === 0) {
|
80
88
|
|
89
|
+
const p = document.createElement('p');
|
90
|
+
|
81
|
-
|
91
|
+
p.textContent = ("Buzz" + " " + number);
|
92
|
+
|
93
|
+
document.body.appendChild(p);
|
82
94
|
|
83
95
|
}
|
84
96
|
|
@@ -97,3 +109,115 @@
|
|
97
109
|
コード
|
98
110
|
|
99
111
|
```
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
以下、parseFloatとisIntegerを自分で実装したコードです。
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```<!DOCTYPE html>
|
122
|
+
|
123
|
+
<html lang="ja">
|
124
|
+
|
125
|
+
<head>
|
126
|
+
|
127
|
+
<meta charset="utf-8">
|
128
|
+
|
129
|
+
<title>FizzBuzz問題</title>
|
130
|
+
|
131
|
+
</head>
|
132
|
+
|
133
|
+
<body>
|
134
|
+
|
135
|
+
<p>
|
136
|
+
|
137
|
+
FizzNum: <input type="text" id="fizzInput" value="" placeholder ="整数値を入力してください">
|
138
|
+
|
139
|
+
</p>
|
140
|
+
|
141
|
+
<p>
|
142
|
+
|
143
|
+
BuzzNum:<input type="text" id="buzzInput" value="" placeholder ="整数値を入力してください">
|
144
|
+
|
145
|
+
</p>
|
146
|
+
|
147
|
+
<button id="btn">実行</button>
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<p>【出力】</p>
|
152
|
+
|
153
|
+
<p>整数値を入力してください</p>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
<script>
|
158
|
+
|
159
|
+
'use strict';
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
const fizzForm = document.getElementById ('fizzInput');
|
164
|
+
|
165
|
+
const buzzForm = document.getElementById ('buzzInput');
|
166
|
+
|
167
|
+
const btn = document.getElementById('btn');
|
168
|
+
|
169
|
+
btn.addEventListener('click', function() {
|
170
|
+
|
171
|
+
const fizzNum = fizzForm.value;
|
172
|
+
|
173
|
+
const buzzNum = buzzForm.value;
|
174
|
+
|
175
|
+
for (let number = 1; number <= 100; number++) {
|
176
|
+
|
177
|
+
if(number % fizzNum === 0 && number % buzzNum === 0 ) {
|
178
|
+
|
179
|
+
const p = document.createElement('p');
|
180
|
+
|
181
|
+
p.textContent = (isInteger.parseFloat("FizzBuzz") + " "+ number);
|
182
|
+
|
183
|
+
document.body.appendChild(p);
|
184
|
+
|
185
|
+
} else if(number % fizzNum === 0) {
|
186
|
+
|
187
|
+
const p = document.createElement('p');
|
188
|
+
|
189
|
+
p.textContent = (isInteger.parseFloat("Fizz") + " " + number);
|
190
|
+
|
191
|
+
document.body.appendChild(p);
|
192
|
+
|
193
|
+
} else if(number % buzzNum === 0) {
|
194
|
+
|
195
|
+
const p = document.createElement('p');
|
196
|
+
|
197
|
+
p.textContent = (isInteger.parseFloat("Buzz") + " " + number);
|
198
|
+
|
199
|
+
document.body.appendChild(p);
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
});
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
</script>
|
210
|
+
|
211
|
+
</body>
|
212
|
+
|
213
|
+
</html>
|
214
|
+
|
215
|
+
コード
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
自分で実装したが、35行目でエラ―発生。
|
222
|
+
|
223
|
+
35行目→ p.textContent = (isInteger.parseFloat("Fizz") + " " + number);
|