dotkpay Posted December 20, 2011 Share Posted December 20, 2011 Hi, I have been sweating with these arrays and I can't seem to see the fault, The function 'document.write() can only output the first value of the array 'car' and it claims the other values of 'car' are undefined whereas it doesn't output anything for any value of array 'date'; Could someone please look through this code for me. <html> <head> <title>Arrays</title> </head> <body> <script type="text/javascript"> var car=new Array(); var home=new Array(); car[0]=1; date[0]="20/12/2011"; car[1]=10; date[1]="20/12/2011"; car[2]=11; date[2]="20/12/2011"; car[3]=12; date[3]="20/12/2011"; car[4]=2; date[4]="20/12/2011"; </script> <script type="text/javascript"> document.write(car[0],"<br>",car[4]); document.write(date[4]); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
gristoi Posted December 20, 2011 Share Posted December 20, 2011 where have you declared the date array? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted December 20, 2011 Share Posted December 20, 2011 i believe this is because immedietaly following your declaration of car[0] you have the line date[0]="20/12/2011"; which will trip an error and render any code after this line useless, due to the fact that you haven't declared the variable date before attempting to use it, as gristoi said. perhaps you meant to declare date instead of home. 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.