rekha Posted January 23, 2008 Share Posted January 23, 2008 Hi Why this following code did not alert the number 8? <script language="JavaScript"> for (j=0; j < 9; j++){ for (i=0; i < 9; i++){ var numToString = parseInt(j+""+i); alert(numToString); } } </script> Regards Rekha http://hiox.org Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 23, 2008 Share Posted January 23, 2008 try this instead: <script language="JavaScript"> for (j=0; j <= 9; j++){ var numToString = parseInt(j); alert(numToString); } </script> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted January 24, 2008 Share Posted January 24, 2008 08 is an octal number. octals range from 0 - 7 Quote Link to comment Share on other sites More sharing options...
rekha Posted January 24, 2008 Author Share Posted January 24, 2008 Hi I have tried the below code and it works. <script language="JavaScript"> for (j=0; j < 9; j++){ var numToString = parseInt(j); } alert(numToString); </script> Thanks for your reply. Regards Rekha http://hiox.org Quote Link to comment Share on other sites More sharing options...
rekha Posted January 24, 2008 Author Share Posted January 24, 2008 Hi, I want to know why the number 8 is not alerting when run the code <script language="JavaScript"> for (j=0; j < 9; j++){ for (i=0; i < 9; i++){ var numToString = parseInt(j+""+i); alert(numToString); } } </script> Regards Rekha http://hiox.org Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted January 24, 2008 Share Posted January 24, 2008 thats a problem with parseInt it does not parse 08 and 09 properly use parseFloat instead following is the code, also I changed some things... <script language="JavaScript"> for (j=0; j < 9; j++){ for (i=0; i < 9; i++){ var numToString = parseFloat(j.toString()+i.toString()); alert(numToString); } } </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.