質問編集履歴

2

文法の修正。

2019/11/22 16:47

投稿

asako1010
asako1010

スコア50

test CHANGED
File without changes
test CHANGED
@@ -184,9 +184,9 @@
184
184
 
185
185
 
186
186
 
187
- 結果、以下のエラーが発生しました。
187
+ 結果、以下のエラーが発生しました。
188
-
188
+
189
- ```index.html:33 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
189
+ ```Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
190
190
 
191
191
  index.html:33 at HTMLButtonElement.<anonymous>
192
192
 
@@ -196,6 +196,10 @@
196
196
 
197
197
 
198
198
 
199
+ 以下のURLのように似たような問題に出会っている人は多いのですが、事例が違うため、なかなか解決に至りません。
200
+
201
+ https://teratail.com/questions/132537
202
+
199
203
 
200
204
 
201
205
  ```<!DOCTYPE html>

1

文法を修正。

2019/11/22 16:47

投稿

asako1010
asako1010

スコア50

test CHANGED
File without changes
test CHANGED
@@ -171,3 +171,177 @@
171
171
  コード
172
172
 
173
173
  ```
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ 上記のコードを修正。
182
+
183
+ <p>を<div>に変更し、idを付けました。
184
+
185
+
186
+
187
+ 結果、以下のエラーが発生しました。。
188
+
189
+ ```index.html:33 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
190
+
191
+ index.html:33 at HTMLButtonElement.<anonymous>
192
+
193
+ コード
194
+
195
+ ```
196
+
197
+
198
+
199
+
200
+
201
+ ```<!DOCTYPE html>
202
+
203
+ <html lang="ja">
204
+
205
+ <head>
206
+
207
+ <meta charset="utf-8">
208
+
209
+ <title>FizzBuzz問題</title>
210
+
211
+ </head>
212
+
213
+ <body>
214
+
215
+ <p>
216
+
217
+ FizzNum: <input type="text" id="fizzInput" value="" placeholder ="整数値を入力してください">
218
+
219
+ </p>
220
+
221
+ <p>
222
+
223
+ BuzzNum:<input type="text" id="buzzInput" value="" placeholder ="整数値を入力してください">
224
+
225
+ </p>
226
+
227
+ <button id="btn">実行</button>
228
+
229
+ <p>【出力】</p>
230
+
231
+ <div id>整数値を入力してください</div>
232
+
233
+ <div id=result></div>
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+ <script>
242
+
243
+ 'use strict';
244
+
245
+ {
246
+
247
+
248
+
249
+ const fizzForm = document.getElementById ('fizzInput');
250
+
251
+ const buzzForm = document.getElementById ('buzzInput');
252
+
253
+ const div = document.getElementById('div');
254
+
255
+
256
+
257
+ const btn = document.getElementById('btn');
258
+
259
+ btn.addEventListener('click', function() {
260
+
261
+
262
+
263
+
264
+
265
+ document.body.removeChild(div);
266
+
267
+ const fizzNum = parseFloat(fizzForm.value);
268
+
269
+ const buzzNum = parseFloat(buzzForm.value);
270
+
271
+
272
+
273
+ if (Number.isInteger(fizzNum) && Number.isInteger(buzzNum))
274
+
275
+ {
276
+
277
+
278
+
279
+ } else {
280
+
281
+ console.log(alert('エラーメッセージ「整数値 を入力してください」'));
282
+
283
+ }
284
+
285
+
286
+
287
+ const result = document.getElementById('result');
288
+
289
+ result.innerHTML = "";
290
+
291
+ for (let number = 1; number <= 100; number++) {
292
+
293
+
294
+
295
+ console.log(Number.isInteger(fizzNum));
296
+
297
+ console.log(Number.isInteger(buzzNum));
298
+
299
+
300
+
301
+ if(number % fizzNum === 0 && number % buzzNum === 0 )
302
+
303
+ {
304
+
305
+ const p = document.createElement('p');
306
+
307
+ p.textContent = ("FizzBuzz" + " "+ number);
308
+
309
+ result.appendChild(p);
310
+
311
+
312
+
313
+ } else if (number % fizzNum === 0) {
314
+
315
+ const p = document.createElement('p');
316
+
317
+ p.textContent = ("Fizz" + " " + number);
318
+
319
+ result.appendChild(p);
320
+
321
+
322
+
323
+ } else if (number % buzzNum === 0) {
324
+
325
+ const p = document.createElement('p');
326
+
327
+ p.textContent = ("Buzz" + " " + number);
328
+
329
+ result.appendChild(p);
330
+
331
+ }
332
+
333
+ }
334
+
335
+ });
336
+
337
+ }
338
+
339
+ </script>
340
+
341
+ </body>
342
+
343
+ </html>
344
+
345
+ コード
346
+
347
+ ```