In the following program when only the White Spaces are entered, it shows ex2
exception value less than 5
, instead of showing ex4
exception This is not a valid number
, I couldn't understand the logic behind it.
<html>
<head>
<title></title>
<script type="text/javascript">
function promptCheck() {
var val=prompt("Enter a Number between 5 and 10","");
try {
if(val=="") {
throw "ex1";
}
else if(val<5) {
throw "ex2";
}
else if(val>10) {
throw "ex3";
}
else if(isNaN(val)) {
throw "ex4";
}
}
catch(err) {
if(err=="ex1") {
alert("You have not entered any value");
}
if(err=="ex2") {
alert("Value less than 5");
}
if(err=="ex3") {
alert("Value greater than 10");
}
if(err=="ex4") {
alert("This is not a valid number");
}
}
}
</script>
</head>
<body>
<input type="button" value="Bring Mouse on Me!" onmouseover="promptCheck()" />
</body>
</html>