javascript throw and catch errors not displaying the expected result -


i have problem try , catch , throw errors. result getting way of mark. code. when type number greater 5 form field, instead of throwing high nothing displayed. , when typed in numbers less 5, shows high, instead of low. in fact of other if conditions does'nt display. except. empty , high. can explain such anomally?

function myfunction() {   var x, message;    message = document.getelementbyid('para');   message.innerhtml =  '';   x = document.getelementbyid('formfield').value;    try {     if (x == "") throw 'empty';      if (x == nan) throw 'not number';      x = number(x);      if (x < 5) throw 'too low';      if (x > 5) throw  'too high';    }     catch(err){     message.innerhtml = 'input ' + err;   } } 

many of guys don't seem understand problem here code direct copy , paste w3schools. not working normally. various if statements supposed throw errors when value input match if statment. rather kind of giving disjointed result. when typed in 2 numbers, instead of throwing input low, throws input high. , when typed in numbers more 5, throws no error, , nan no response javascript.

is there out there can understand talking about? think should run code yourselves , please educate me confuse.

try debug in console:

nan === nan 

and wonder :) second, mistake - must convert x int:

x = parseint(document.getelementbyid('formfield').value); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -