Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a function, called spin, in the head section that takes no parameters but

ID: 3781180 • Letter: C

Question

Create a function, called spin, in the head section that takes no parameters but returns a random number between 0 and 6 inclusive. Call this function three times and assign it to different variables. Create another function, called evaluateGame, that takes three parameters and returns the a integer. (ALL WINS are evaluated from left to right - 4, 0, 0 would be a losing game) If there are three 0's for the random values win 14 If there are three of any other number win 7 If there are two 0'sin the first and second spot them win 4. If there are two of any other number in the first two spots win 2. If there are is a 0 in the first spot then win 1. The function will return the win score. Create a function that takes in a single number. Based on that number you get print picture. (0 is cherry, the rest do not matter). Underneath the three pictures print the winning score. Put the above requirements in either a for loop or a while loop and do it three times. (Therefore, you should have three slot machines.) Put a hyperlink at the bottom that links to the same page, make the text say "spin". Total

Explanation / Answer

CODE:

<html>
<head>
<title> Slot Machine</title>
<script type="text/javascript" src="http://balance3e.com/random.js"></script>
<script type="text/javascript">
var spinCount = 0;
var images = ['lemon', 'cherry', 'bar'];

function SpinSlots()
// Assumes: slot images are in http://balance3e.com/Images
// Resultes: displays 3 random slot images
{
   // if not spinning, pick a random number of spins
   if ( spinCount == 0 ) spinCount = 10 + Math.floor( 20 * Math.random() );

   var slot1 = RandomOneOf(images);
   var slot2 = RandomOneOf(images);
   var slot3 = RandomOneOf(images);

   document.getElementById('slot1Img').src =
   'http://balance3e.com/Images/' + slot1 + '.jpg';
   document.getElementById('slot2Img').src =
   'http://balance3e.com/Images/' + slot2 + '.jpg';
   document.getElementById('slot3Img').src =
   'http://balance3e.com/Images/' + slot3 + '.jpg';

--spinCount;
if ( spinCount > 0 )
{
setTimeout(SpinSlots, 50);
return;
}

   // assume the person loses:  
var credits = parseInt(document.getElementById('credits').innerHTML);
--credits; // always costs 1 credit to play

   var msg = "You lose!";
var color = "red";

   if (slot1 == slot2 && slot2 == slot3)
   {
   // oh nuts, she/he won
   credits += 13;
msg = "You win 13 credits!";
color = "green";
   }
    // update credits display and win/lose message
   document.getElementById('credits').innerHTML = credits;
var msgspan = document.getElementById("message");
msgspan.innerHTML = msg;
msgspan.style.color = color;

if ( credits <= 0 )
{
alert("You lost all your money!");
location.href = "http://www.gamblersanonymous.org";
}
}
</script>
</head>

<body>
<div>
<p>
   <img id="slot1Img" border=1 alt="slot image"
   src="http://balance3e.com/Images/cherry.jpg">
   <img id="slot2Img" border=1 alt="slot image"
   src="http://balance3e.com/Images/lemon.jpg">
   <img id="slot3Img" border=1 alt="slot image"
   src="http://balance3e.com/Images/bar.jpg">

</p>
<input type="button" value="Click to Spin">
<br/><br/>
<span id="message"></span>
<br/><br/>
Credits Remaining: <spin id="credits">20</span>
</p>
</div>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote