The code given below should give different output on the basis of the input values but it is not working.
function myFunction() {
let x = document.getElementById("demo").value;
let y;
if (x == "") {
y = "The field is Empty";
} else if (isNaN(x)) {
y = "Input is not a number";
} else if (x < 5) {
y = "The number is too low";
} else(x > 10) {
y = "The number is too big";
}
document.getElementById("p01").innerHTML = y;
}
<input id="demo" type="text">
<button type="button" onclick="myFunction()">Test Input</button>
<p id="p01"></p>
>Solution :
You are putting a condition in the else statement: else (x > 10) which can’t be done. Change it to else if (x > 10) and you should be good to go.