|
I am trying to create a pick-4 lotto which uses loops. You are supposed to enter 4 numbers 0-9 and create how many times it takes for that series to come up. I am not very good at javascript and have been having a lot of trouble on just a couple things. Any help would be greatly appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <! Programmer: > <! Class: CIS 1207 Programmin Logic & Design > <! Assignment: Homework Program #7> <head> <title>Assignment#7 Loops</title> <script type="text/javascript" src="http://prenhall.com/reed/random.js"> </script> <script type="text/javascript"> function PickNum() { var Pick1, Pick2, Pick3, Pick4; var Roll1, Roll2, Roll3, Roll4; var Count; Pick1=parseFloat (document.LottoFrm.txtPick1.value); Pick2=parseFloat (document.LottoFrm.txtPick2.value); Pick3=parseFloat (document.LottoFrm.txtPick3.value); Pick4=parseFloat (document.LottoFrm.txtPick4.value); Count=document.LottoFrm.txtcount.value; do { Roll1=RandomInt(0,9); Roll2=RandomInt(0,9); Roll3=RandomInt(0,9); Roll4=RandomInt(0,9); } while (Roll1!=Pick1 || Roll2!=Pick2 || Roll3!=Pick3 || Roll4!=Pick4); count++; } </script> </head> <body bgcolor="blue" style="color:white"> <h3 style="text-align:center">CNM Lotto</h3> <form name="LottoFrm" style="text-align:center"> <br/> Pick-4 Lottery Numbers: <input text="text" name="txtPick1" size=5 value="" ;"/> <input text="text" name="txtPick2" size=5 value="" "/> <input text="text" name="txtPick3" size=5 value="" "/> <input text="text" name="txtPick4" size=5 value="" "/> <br/><br/> <input type="button" value="Click Here to Begin Drawing" onClick ="PickNum();"/> <input type="text" name="txtCount" size=5 value=""/> </form> </body> </html>
|
# ¿ Apr 22, 2009 17:29 |
|
|
# ¿ May 7, 2024 15:14 |
|
Kekekela posted:Start by resolving your javascript errors. For one, I don't think document.LottoFrm.txtcount will work, you can give the text box an id and call document.getElementById('txtcount') instead. (The latest version of firefox requires you to go to Tools>ErrorConsole to see the errors, not sure about IE et al) I wasn't trying to get my homework done for me. Just needed a suggestions and the ones provided did very well. Here is my corrected code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <! Programmer: > <! Class: CIS 1207 Programmin Logic & Design > <! Assignment: Homework Program #7> <head> <title>Assignment#7 Loops</title> <script type="text/javascript" src="http://prenhall.com/reed/random.js"> </script> <script type="text/javascript"> function PickNumber() { var Pick1, Pick2, Pick3, Pick4; var Roll1, Roll2, Roll3, Roll4; var Count; Pick1=parseFloat (document.LottoFrm.txtPick1.value); Pick2=parseFloat (document.LottoFrm.txtPick2.value); Pick3=parseFloat (document.LottoFrm.txtPick3.value); Pick4=parseFloat (document.LottoFrm.txtPick4.value); Count=0; do { Roll1=RandomInt(0,9); Roll2=RandomInt(0,9); Roll3=RandomInt(0,9); Roll4=RandomInt(0,9); Count++; } while (Roll1!=Pick1 || Roll2!=Pick2 || Roll3!=Pick3 || Roll4!=Pick4); document.LottoFrm.txtCount.value=Count; } </script> </head> <body bgcolor="blue" style="color:green"> <h3 style="text-align:center">CNM Lotto</h3> <form name="LottoFrm" style="text-align:center"> <br/> Pick-4 Lottery Numbers: <input text="text" name="txtPick1" size=5 value="" /> <input text="text" name="txtPick2" size=5 value="" /> <input text="text" name="txtPick3" size=5 value="" /> <input text="text" name="txtPick4" size=5 value="" /> <br/><br/> Click on the button to perform Pick-4 drawings until sequence appears <br/><br/> <input type="button" onClick="PickNumber();" value="Click Here to Begin Drawing"/> <br/><br/> Number of Picks: <input type="text" name="txtCount" size=5 value="" /> </form> </body> </html> Thanks for the help friends.
|
# ¿ Apr 23, 2009 04:31 |