Home Up Contents

JS SlotMachine
JS SlotMachine VBS SlotMachine Quadratic Formula

 

 

SLOT MACHINE (Java Script Version)



Your remaining credit : $

(press if you run out of money)

 

JS Code

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
// 
// Random Generating Function
//
function RandGen()
{
  document.Slot.prizemessage.value = "... wait";
  if (document.Slot.credit.value < 1)
  {
     document.Slot.prizemessage.value = "Get more credit before you play on!  Press button for more credit"
     //alert("Get more credit before you play on!\n\n'Press button for more credit");
  }
  else
  { 
   document.Slot.prizemessage.value = "... wait";
   for (i=0; i< 100; i++)
   {
     document.Slot.number1.value = Math.floor(10*Math.random());
     document.Slot.number2.value = Math.floor(10*Math.random());
     document.Slot.number3.value = Math.floor(10*Math.random());
   }
  PrizeMessage(document.Slot.number1.value,
               document.Slot.number2.value,
               document.Slot.number3.value);
  } 
}
function PrizeMessage(num1, num2, num3)
{
  if ((num1==num2) && (num1==num3))
  { 
  document.Slot.prizemessage.value = "Congratulations, three numbers equal! You won $20!";
  document.Slot.credit.value = (eval(document.Slot.credit.value) + 19); // +$20 minus $1 stake
  }
  else 
  {
    if ((num1==num2) || (num1==num3)  || (num2==num3))
    {
    document.Slot.prizemessage.value = "Two numbers equal! You won $2!";
    document.Slot.credit.value = (1 + eval(document.Slot.credit.value)); // +$2 minus $1 stake
    }
    else
    {
    document.Slot.prizemessage.value = "Sorry, you lost $1!";
    document.Slot.credit.value = (document.Slot.credit.value - 1);
    } 
  }
  
}
</Script>
</head>
<body>
<h3>
SLOT MACHINE <font color="#0000FF">(Java Script Version)</font></h3>
<p><form name=Slot>
<input id=text1 name=number1  size=4 readonly title="yyyy">
<input id=text1 name=number2 size=4 readonly>
<input id=text1 name=number3 size=4  readonly>
<br><input id=button1 name=button1  type=button value="Play for $1"
           onclick = "RandGen()">
<br>
<input id=text1 name=prizemessage size=70  readonly>
<p>
<b> Your remaining credit :</b> $<input id=text1 name=credit size=4 readonly value=10>
<br>
<input id=button2 name=button2  type=button value="Get $10 to play"
           onclick = "document.Slot.credit.value = 10"> <br> (press if you run out of money)
</form>
<pre style="word-spacing: 0; line-height: 100%; margin-right: 0; margin-top: 0; margin-bottom: 0">&nbsp;</pre>
</body>
</html>

Send mail to kurthess@waikato.ac.nz with questions or comments about this web site.
Copyright © January, 2009 Kurt Hess, University of Waikato
Last modified: 13-Jan-2009