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 Link to comment https://forums.phpfreaks.com/topic/87366-alert-error/ 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> Link to comment https://forums.phpfreaks.com/topic/87366-alert-error/#findComment-447328 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 Link to comment https://forums.phpfreaks.com/topic/87366-alert-error/#findComment-447429 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 Link to comment https://forums.phpfreaks.com/topic/87366-alert-error/#findComment-447490 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 Link to comment https://forums.phpfreaks.com/topic/87366-alert-error/#findComment-447666 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> Link to comment https://forums.phpfreaks.com/topic/87366-alert-error/#findComment-447668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.