soycharliente Posted June 25, 2007 Share Posted June 25, 2007 Can someone tell me what's wrong with this code? <html> <head> <title>Untitled Document</title> <script language="text/javascript"> function repeatword() { var string; for (var i = 0; i < 100; i++) { string += "hello "; } return string; } </script> </head> <body> <script language="text/javascript"> document.write(repeatword()); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
akitchin Posted June 25, 2007 Share Posted June 25, 2007 try alert()ing the string before returning it, to see if the function is actually running properly. one tool i find useful when debugging javascript is the javascript console in firefox. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 25, 2007 Author Share Posted June 25, 2007 Alert doesn't pop up. I'm using the web developer tool bar for FF and it says no errors. Quote Link to comment Share on other sites More sharing options...
akitchin Posted June 25, 2007 Share Posted June 25, 2007 try changing your script tag - it should be the type attribute, not language: <script type="text/javascript"> also try running the function directly after defining it, rather than in the body of the document. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 25, 2007 Author Share Posted June 25, 2007 WOW. Noob mistake. Thanks. 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.