revision:
The Number.isInteger() static method determines whether the passed value is an integer.
Number.isInteger(value)
Parameters:
value : required.The value to be tested for being an integer.
function fits(x, y) { if (Number.isInteger(y / x)) { return 'Fits!'; } return 'Does NOT fit!'; } console.log(fits(5, 10)); // Expected output: "Fits!" console.log(fits(5, 11)); // Expected output: "Does NOT fit!"
<div> <p id="integer-1"></p> <p id="integer-2"></p> <p id="integer-3"></p> <p id="integer-4"></p> <p id="integer-5"></p> <p id="integer-6"></p> <p id="integer-7"></p> <p id="integer-8"></p> <p id="integer-9"></p> <p id="integer-10"></p> <p id="integer-11"></p> <p id="integer-12"></p> <p id="integer-13"></p> <p id="integer-14"></p> <p id="integer-15"></p> <p id="integer-16"></p> <p id="integer-17"></p> </div> <script> document.getElementById("integer-1").innerHTML = "Number.isInteger(0) : " + Number.isInteger(0); // true document.getElementById("integer-2").innerHTML = "Number.isInteger(1) : " + Number.isInteger(1); // true document.getElementById("integer-3").innerHTML = "Number.isInteger(-100000) : " + Number.isInteger(-100000); // true document.getElementById("integer-4").innerHTML = "Number.isInteger(99999999999999999999999) : " + Number.isInteger(99999999999999999999999); // true document.getElementById("integer-5").innerHTML = "Number.isInteger(0.1) : " + Number.isInteger(0.1); // false document.getElementById("integer-6").innerHTML = "Number.isInteger(Math.Pi) : " + Number.isInteger(Math.PI); // false document.getElementById("integer-7").innerHTML = "Number.isInteger(NaN) : " + Number.isInteger(NaN); // false document.getElementById("integer-8").innerHTML = "Number.isInteger(Infinity) : " + Number.isInteger(Infinity); // false document.getElementById("integer-9").innerHTML = "Number.isInteger(-Infinity) : " + Number.isInteger(-Infinity); // false document.getElementById("integer-10").innerHTML = "Number.isInteger('10') : " + Number.isInteger('10'); // false document.getElementById("integer-11").innerHTML = "Number.isInteger(true) : " + Number.isInteger(true); // false document.getElementById("integer-12").innerHTML = "Number.isInteger(false) : " + Number.isInteger(false); // false document.getElementById("integer-13").innerHTML = "Number.isInteger([1]) : " + Number.isInteger([1]); // false document.getElementById("integer-14").innerHTML = "Number.isInteger(5.0) : " + Number.isInteger(5.0); // false document.getElementById("integer-15").innerHTML = "Number.isInteger(5.000000000000001) : " + Number.isInteger(5.000000000000001); // false document.getElementById("integer-16").innerHTML = "Number.isInteger(5.0000000000000001) : " + Number.isInteger(5.0000000000000001); // true, because of loss of precision document.getElementById("integer-17").innerHTML = "Number.isInteger(4500000000000000.1) : " + Number.isInteger(4500000000000000.1); // true, because of loss of precision </script>