teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

文法の修正。

2019/11/22 16:47

投稿

asako1010
asako1010

スコア50

title CHANGED
File without changes
body CHANGED
@@ -91,12 +91,14 @@
91
91
  上記のコードを修正。
92
92
  <p>を<div>に変更し、idを付けました。
93
93
 
94
- 結果、以下のエラーが発生しました。
94
+ 結果、以下のエラーが発生しました。
95
- ```index.html:33 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
95
+ ```Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
96
96
  index.html:33 at HTMLButtonElement.<anonymous>
97
97
  コード
98
98
  ```
99
99
 
100
+ 以下のURLのように似たような問題に出会っている人は多いのですが、事例が違うため、なかなか解決に至りません。
101
+ https://teratail.com/questions/132537
100
102
 
101
103
  ```<!DOCTYPE html>
102
104
  <html lang="ja">

1

文法を修正。

2019/11/22 16:47

投稿

asako1010
asako1010

スコア50

title CHANGED
File without changes
body CHANGED
@@ -84,4 +84,91 @@
84
84
  </body>
85
85
  </html>
86
86
  コード
87
+ ```
88
+
89
+
90
+
91
+ 上記のコードを修正。
92
+ <p>を<div>に変更し、idを付けました。
93
+
94
+ 結果、以下のエラーが発生しました。。
95
+ ```index.html:33 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
96
+ index.html:33 at HTMLButtonElement.<anonymous>
97
+ コード
98
+ ```
99
+
100
+
101
+ ```<!DOCTYPE html>
102
+ <html lang="ja">
103
+ <head>
104
+ <meta charset="utf-8">
105
+ <title>FizzBuzz問題</title>
106
+ </head>
107
+ <body>
108
+ <p>
109
+ FizzNum: <input type="text" id="fizzInput" value="" placeholder ="整数値を入力してください">
110
+ </p>
111
+ <p>
112
+ BuzzNum:<input type="text" id="buzzInput" value="" placeholder ="整数値を入力してください">
113
+ </p>
114
+ <button id="btn">実行</button>
115
+ <p>【出力】</p>
116
+ <div id>整数値を入力してください</div>
117
+ <div id=result></div>
118
+
119
+
120
+
121
+ <script>
122
+ 'use strict';
123
+ {
124
+
125
+ const fizzForm = document.getElementById ('fizzInput');
126
+ const buzzForm = document.getElementById ('buzzInput');
127
+ const div = document.getElementById('div');
128
+
129
+ const btn = document.getElementById('btn');
130
+ btn.addEventListener('click', function() {
131
+
132
+
133
+ document.body.removeChild(div);
134
+ const fizzNum = parseFloat(fizzForm.value);
135
+ const buzzNum = parseFloat(buzzForm.value);
136
+
137
+ if (Number.isInteger(fizzNum) && Number.isInteger(buzzNum))
138
+ {
139
+
140
+ } else {
141
+ console.log(alert('エラーメッセージ「整数値 を入力してください」'));
142
+ }
143
+
144
+ const result = document.getElementById('result');
145
+ result.innerHTML = "";
146
+ for (let number = 1; number <= 100; number++) {
147
+
148
+ console.log(Number.isInteger(fizzNum));
149
+ console.log(Number.isInteger(buzzNum));
150
+
151
+ if(number % fizzNum === 0 && number % buzzNum === 0 )
152
+ {
153
+ const p = document.createElement('p');
154
+ p.textContent = ("FizzBuzz" + " "+ number);
155
+ result.appendChild(p);
156
+
157
+ } else if (number % fizzNum === 0) {
158
+ const p = document.createElement('p');
159
+ p.textContent = ("Fizz" + " " + number);
160
+ result.appendChild(p);
161
+
162
+ } else if (number % buzzNum === 0) {
163
+ const p = document.createElement('p');
164
+ p.textContent = ("Buzz" + " " + number);
165
+ result.appendChild(p);
166
+ }
167
+ }
168
+ });
169
+ }
170
+ </script>
171
+ </body>
172
+ </html>
173
+ コード
87
174
  ```