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> Link to comment https://forums.phpfreaks.com/topic/57090-solved-function-not-running/ 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. Link to comment https://forums.phpfreaks.com/topic/57090-solved-function-not-running/#findComment-282077 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. Link to comment https://forums.phpfreaks.com/topic/57090-solved-function-not-running/#findComment-282085 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. Link to comment https://forums.phpfreaks.com/topic/57090-solved-function-not-running/#findComment-282089 Share on other sites More sharing options...
soycharliente Posted June 25, 2007 Author Share Posted June 25, 2007 WOW. Noob mistake. Thanks. Link to comment https://forums.phpfreaks.com/topic/57090-solved-function-not-running/#findComment-282094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.