回答編集履歴
1
追記
test
CHANGED
@@ -93,3 +93,91 @@
|
|
93
93
|
|
94
94
|
|
95
95
|
```
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```diff
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
'use strict';
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
// Fizz Buzz計算式
|
110
|
+
|
111
|
+
document.querySelector('button').addEventListener('click', () => {
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
+ document.getElementById('output').innerHTML = ""; //<-追加
|
116
|
+
|
117
|
+
for(let i = 1; i < 101; i++) {
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
// inputに入力された値を代入
|
122
|
+
|
123
|
+
let form1 = document.getElementById('fizznumber');
|
124
|
+
|
125
|
+
let fizz = form1.value;
|
126
|
+
|
127
|
+
let form2 = document.getElementById('buzznumber');
|
128
|
+
|
129
|
+
let buzz = form2.value;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
let x = fizz;
|
134
|
+
|
135
|
+
let y = buzz;
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// documentに計算結果を表示する
|
140
|
+
|
141
|
+
let output = document.getElementById('output');
|
142
|
+
|
143
|
+
let div = document.createElement('div');
|
144
|
+
|
145
|
+
let result = output.appendChild(div);
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
// 計算式
|
150
|
+
|
151
|
+
if (!isNaN(x) && !isNaN(y)) { // 数字かどうか調べる
|
152
|
+
|
153
|
+
if (i % (x * y) === 0) {
|
154
|
+
|
155
|
+
result.innerHTML = `fizzBuzz${i}`;
|
156
|
+
|
157
|
+
} else if (i % x === 0) {
|
158
|
+
|
159
|
+
result.innerHTML = `fizz${i}`;
|
160
|
+
|
161
|
+
} else if (i % y === 0) {
|
162
|
+
|
163
|
+
result.innerHTML = (`Buzz${i}`);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
} else {
|
168
|
+
|
169
|
+
result.innerHTML = '数字を入力して下さい';
|
170
|
+
|
171
|
+
return
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
});
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
```
|