Jump to content

Parseint Nan Detection Not Working


Recommended Posts


function gmn(event) {var myNum = Math.floor(Math.random()*101);changeText("lo", "0");changeText("hi", "100");changeText("ans", myNum);}function changeText(text, withh) {var textFieldToChange = document.getElementById(text);var newTextFieldText = withh;					textFieldToChange.value = newTextFieldText;}function getText(text) {var textAreaValue = document.getElementById(text);return parseInt(textAreaValue.value);}function pInt(thing) {return parseInt(thing);}function alerttext(event) {var gess = getText("guess");gess = pInt(gess);var an = getText("ans");an = pInt(an);//NaN detection: \/if (gess == "NaN") {alert("bad");} else {alert(gess);if (gess < an) {changeText("lo", gess);} else if (gess > an) {changeText("hi", gess);}}changeText("guess", "");}function winn() {alert("YouWin!");}

For some reason, when I start it, enter a number, and hit guess, I get an alert "NaN" which means that the NaN detection didn't work correctly.Does anyone know why?HiGuy

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...