Lately, I've been working on a "spinner" that increments and decrements a number by 1 each time. However, I'm struggling to add validation to the program so that it only accepts integers (no decimals). I've tried looking into NaN and parseValue(s) solutions, but haven't been able to integrate them into my script successfully. Any assistance with this would be greatly appreciated. The code in the example provided functions as intended, but I specifically need help with adding the validation.
CODE: HTML
<!DOCTYPE html>
<html>
<head>
<h1>Spinners in JavaScript</h1>
</head>
<body>
<p id="textDisplay()">0</p>
<div align="middle">
<button onclick="spinUp()">+1</button>
<button onclick="spinDown()">-1</button>
</div>
</body>
</html>
JavaScript
currentNumber = 0;
function spinUp() {
if(currentNumber==100){
currentNumber = 0;
document.getElementById("textDisplay").innerHTML = currentNumber;
} else if(currentNumber < 100) {
currentNumber++
document.getElementById("textDisplay").innerHTML = currentNumber;
}
}
function spinDown() {
if(currentNumber>0){
currentNumber--;
document.getElementById("textDisplay").innerHTML = currentNumber;
} else if(currentNumber<=0){
window.alert("Too low! Higher!");
currentNumber++;
document.getElementById("textDisplay").innerHTML = currentNumber;
}
}