xcoderx Posted December 18, 2009 Share Posted December 18, 2009 to display even numbers 1-50 im using this var even=0; for (even=1;even<=50;even++) { alert(even); } now how do i display odd numbers 1-20 kindly help me out Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/ Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 ok got it lol var even=0; for (even=1;even < 20;even++) { alert(even++); } Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-979902 Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 help again internal javascript not displaying what wrong am i doing? <html> <head> <title>ODD/EVEN/AVEREGE</title> <script type="text/javascript"> function even() { var even even = document.results.even.value; var even=0; for (even=1;even < 50;even++) { alert(even); } function odd() { var odd odd = document.results.odd.value; var odd=0; for (odd=1;odd < 20;odd++) { alert(odd++); } </script> </head> <body> <form action="#" name="results" method="post"> <input type="button" name="even" value="Even numbers 1-50" onClick="even();"/> <input type="button" name="odd" value="Odd numbers 1-20" onClick="odd();"/> <input type="reset" value="reset"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-979913 Share on other sites More sharing options...
RichardRotterdam Posted December 18, 2009 Share Posted December 18, 2009 You probably would have seen some trouble by just indenting your code. function even() { var even even = document.results.even.value; var even=0; for (even=1;even < 50;even++) { alert(even); } // see something missing here? function odd() { var odd odd = document.results.odd.value; var odd=0; for (odd=1;odd < 20;odd++) { alert(odd++); } // see something missing here? Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980019 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 no no really sure what ur donghere. must need to specify a bit more hon Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980062 Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2009 Share Posted December 18, 2009 something like this should work <html> <head> <title>ODD/EVEN/AVEREGE</title> <script type="text/javascript"> function even() { for (even=2;even <= 50;even=even+2) { alert(even); } } function odd() { for (odd=1;odd < 20;odd=odd+2) { alert(odd); } } </script> </head> <body> <form action="#" name="results" method="post"> <input type="button" name="evenbutton" value="Even numbers 1-50" onClick="even();"/> <input type="button" name="oddbutton" value="Odd numbers 1-20" onClick="odd();"/> <input type="reset" value="reset"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980067 Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 please help me when i click button nothing is displaying <html> <head> <title>ODD/EVEN/AVEREGE</title> <script type="text/javascript"> function even() { var even even = document.results.even.value; var even=0; for (even=1;even < 50;even++) { alert(even); } function odd() { var odd odd = document.results.odd.value; var odd=0; for (odd=1;odd < 20;odd++) { alert(odd++); } </script> </head> <body> <input type="button" name="odd" value="Even numbers 1-50" onclick="eve();"/> <input type="button" name="odd" value="Odd numbers 1-20" onclick="odd();"/> <input type="reset" value="reset"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980069 Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2009 Share Posted December 18, 2009 see my post above that code works Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980076 Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 yes i worked what was i ding wrong? my head started to pain lol Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980077 Share on other sites More sharing options...
RichardRotterdam Posted December 18, 2009 Share Posted December 18, 2009 this is one of the things that might caused it onclick="eve() when your function name is even Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980082 Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 nah not that Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980086 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 what exactly r u trying to acumplish with thies? Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980089 Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 nothin im new to all this i recently started my javascript class and this was a class assignment by my faculty Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980097 Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2009 Share Posted December 18, 2009 oh dear I just helped you out with your homework Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980100 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 no hon whats the pint of the scrapt? Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980101 Share on other sites More sharing options...
xcoderx Posted December 18, 2009 Author Share Posted December 18, 2009 but i was stuck and thanks soo much all evening i was stuck tryin many ways but it never alerted :-( Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980105 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 im sorry i dont get it Quote Link to comment https://forums.phpfreaks.com/topic/185601-urgent-help-alert-even-and-odd-numbers-with-for-loop-please/#findComment-980113 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.