JavaScript · Viking Code School

Roulette in JavaScript

The second portion of the first assignment for the “Falling in Love with JavaScript” course of Viking Code School‘s advanced prep involved creating a simple roulette game. The player starts with a bankroll of $1,000 and is able to choose an amount to bet and a type of bet from the following options:

  • single number 00, 0-36 (payout 35:1)
  • even, odd, 1-18, or 19-36 (payout 1:1)
  • 1st 12, 2nd 12, or 3rd 12 (payout 2:1)

The game users JavaScript prompts rather than an HTML interface. Aside from the main game prompts, the game also asks the user if they would like to continue playing after each spin and prohibits a user from playing further if their bankroll drops to zero. The code I wrote uses if statements and for loops to identify the types of bets. The Math.floor and Math.random (multiplied by 37 for the numbers 00 and 0-36) methods are used for the spin feature. A switch statement with cases for the different outcomes of the bets is used in combination with a boolean and additional if statements and for loops to assign the correct lose or winnings. My GitHub repo for this project can be viewed here, while the game can be played here. My source code is provided below.



One thought on “Roulette in JavaScript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s