Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Divinorum
Nov 18, 2002
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>

Adbot
ADBOT LOVES YOU

Divinorum
Nov 18, 2002

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)

Then once the syntax is correct start looking at your logic. It may be doing what you want already, I just glanced pretty quickly, but from what you're describing you want to be reading the count value and displaying it in the txtcount field after you've processed the main loop, instead of reading it in from the txtcount field before the loop (should there even be anything in that field at this point? seems like this is where your answer goes, not where you get user input)


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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply