Home>
I want to change the specification so that calculation does not start as shown in the photo below when a non-integer value is entered in one or both of the forms.
I have investigated, but no matter how I am corrected, even if it is an integer value, even if I enter an integer value, the calculation starts and I am worried.
<! DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>FizzBuzz issue</title>
</head>
<body>
<p>
FizzNum:<input type = "text" value = "" placeholder = "Please enter an integer value">
</p>
<p>
BuzzNum:<input type = "text" value = "" placeholder = "Please enter an integer value">
</p>
<button>Execute</button>
<p>[Output]</p>
<p>Please enter an integer value</p>
<script>
'use strict';
{
const fizzForm = document.getElementById ('fizzInput');
const buzzForm = document.getElementById ('buzzInput');
const p = document.getElementById ('p');
const btn = document.getElementById ('btn');
btn.addEventListener ('click', function () {
document.body.removeChild (p);
const fizzNum = parseFloat (fizzForm.value);
const buzzNum = parseFloat (buzzForm.value);
if (Number.isInteger (fizzNum)&&Number.isInteger (buzzNum))
{
} else {
console.log (alert ('Error message' Please enter an integer value ''));
}
const result = document.getElementById ('result');
result.innerHTML = "";
for (let number = 1;number<= 100;number ++) {
console.log (Number.isInteger (fizzNum));
console.log (Number.isInteger (buzzNum));
if (number% fizzNum === 0&&number% buzzNum === 0)
{
const p = document.createElement ('p');
p.textContent = ("FizzBuzz" + "" + number);
result.appendChild (p);
} else if (number% fizzNum === 0) {
const p = document.createElement ('p');
p.textContent = ("Fizz" + "" + number);
result.appendChild (p);
} else if (number% buzzNum === 0) {
const p = document.createElement ('p');
p.textContent = ("Buzz" + "" + number);
result.appendChild (p);
}
}
});
}
</script>
</body>
</html>
Code
-
Answer # 1
-
Answer # 2
const result = document.getElementById ('result'); result.innerHTML = ""; for (let number = 1;number<= 100;number ++) { console.log (Number.isInteger (fizzNum)); console.log (Number.isInteger (buzzNum)); if (number% fizzNum === 0&&number% buzzNum === 0) { const p = document.createElement ('p'); p.textContent = ("FizzBuzz" + "" + number); result.appendChild (p); } else if (number% fizzNum === 0) { const p = document.createElement ('p'); p.textContent = ("Fizz" + "" + number); result.appendChild (p); } else if (number% buzzNum === 0) { const p = document.createElement ('p'); p.textContent = ("Buzz" + "" + number); result.appendChild (p); } }
should be in
if (Number.isInteger (fizzNum)&&Number.isInteger (buzzNum))
Related articles
- # if you change the value once entered with the score input function with javascript, it will become nan
- javascript - about validation of the value entered in the input tag
- javascript - i want to display the value entered in the created form in slack with incoming webhooks
- i want to change the result of repetition with the value checked by javascript
- javascript - when i display the value entered in the form, it is displayed as undefined
- i want to convert the value entered in the javascript form to json and display it on the confirmation screen
- javascript - i want to make a program in which the entered value is calculated automatically
- javascript - i want to change the text depending on the boolean value in react
- javascript - i want to change the value in the web page when the tact switch is pressed in flask, python, js
- javascript - i want to receive and display a value in a dialog box
- javascript - i want to express a function registered as a value using a method name for an object with an arrow function
- reactjs - [react] even if you change the value of the object using objectassign ({},), it is not rendered and the checkbox does
- javascript - about the return value of async
- ruby - i want to change the way of arranging the hash value data obtained from the table
- javascript - i want to change the display range of the array
- javascript - i want to use a value initialized in one class in another unrelated class with no arguments
- cannot set transform: rotate value from variable in javascript
- javascript - i don't know the value of this
- javascript value property and value attribute difference
- javascript - i want to change the process using check in jquery
Trends
A message is displayed after confirming the state of the price, but it will proceed as it isnot aborted.