Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Javascript Assignment In a Lotto game, the total number of balls is n and the number of balls drawn without replacement is k. Before the

Javascript Assignment

  • In a Lotto game, the total number of balls is n and the number of balls drawn without replacement is k. Before the balls are drawn, you choose k numbers from 1 to n, sorted in order from smallest to largest. When the balls are drawn, if they match the numbers that you picked, you win.
  • The payoff depends on the number of winners and elapsed time since there was at least one winner.
  • Your job is to design a user interface that displays the lotto balls that are drawn when drawing up to balls from 5 total of 30 balls.
  • Use a button to perform the drawing.
  • Use a Lotto class object in the script lotto-class.js to simulate drawing the balls.
  • The Lotto class object draws the balls with replacement and sorts them in numeric order before outputting them.
  • Extra Credit: Allow the user to choose how many balls from which to draw and how many balls to draw. This provides a variety of Lotto games to play. lotto-class.js
  • ---------------------
  • // Lotto Class for Project 3 // Draw Lotto balls with replacement. // Sort balls for output. class Lotto { // Set number of all balls (<= 30) and number of // balls drawn (<= 6). constructor(numAllBalls, numBallsDrawn) { if (numAllBalls <= 30) { this.numAllBalls = numAllBalls; } else { this.numAllBalls = 30; } if (numBallsDrawn <= 6) { this.numBallsDrawn = numBallsDrawn; } else { this.numBallsDrawn = 6; } // console.log(this.numAllBalls + " " + // this.numBallsDrawn); } selectBalls( ) { // Set of balls to select this.balls = [ ]; // Balls actually selected without // replacement this.drawnBalls = [ ]; // Construct array containing balls // from which to select. for(let i = 1; i <= this.numAllBalls; i++) { this.balls.push(i); } // Draw and sort balls to determine winning // Lotto numbers. for(let i = 0; i < this.numBallsDrawn; i++) { var randVal = Math.floor(Math.random( ) * this.balls.length); var ballNum = this.balls[randVal]; this.drawnBalls.push(parseInt(ballNum)); this.balls.splice(randVal, 1); } // Less than function must be provided so that // balls are sorted in numeric order. This // function is like the Python __lt__ method. this.drawnBalls.sort((a, b) => a - b); // console.log(this.drawnBalls); } // Return ith selected ball. getBall(i) { if (1 <= i && i <= this.numBallsDrawn) { return this.drawnBalls[i - 1]; } else { return null; } } // Return list of drawn balls as a string. toString( ) { var output = this.drawnBalls[0].valueOf( ); for(let i = 1; i < this.numBallsDrawn; i++) { output += " " + this.drawnBalls[i]; } return output; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

=+9. Their computer is similar __________ ours.

Answered: 1 week ago