I have a text box and button where a User must input a mark between 1 and 10. After such inner HTML displays the mark as a percentage.
I am having a bit of difficult getting myisNaN
function to work within my code for numbers that exceed 10 or for values that are indeed not numbers.
The code works well except for this specific part and I am wondering where I am going wrong.
<script>
function myFunction() {
var x, text;
// Get the value of the input field with id="numb"
x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Your final mark is";
}
document.getElementById("demo").innerHTML = (x) * 10 + "%";
}
</script>
<body>
<h1>JavaScript to Validate Input</h1>
<p>Enter your mark between 1 and 10:</p>
<input id="numb">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
</body>