*Modulus divides two numbers and returns the remainder.
A single line comment is written like this:
A multiple line comment is written like this:
Comment everything so you don't forget what something does!
An array is a numbered list of data. It has different positions and a value can be stored at each position. The first position is number 0.
To access a particular position in an array to set or retrieve its value, write
To set an entire array, write
To find the size of an array, write
Boolean comparisons:
*Equals is not just =. = is used for setting variables. === is used for comparisons.
Combining boolean comparisons:
Remember to use parentheses to separate components of longer expressions.
*The vertical line can be typed by pressing shift and \. \ is located above your return/enter key.
A for loop is a modification of a while loop that makes it easier to do something a certain number of times. The basic for loop structure is:
This for loop will do something three times (once at counter === 0, once at 1, and once at 2). Make sure the boundary condition will be reached or you will get an infinite loop and the program will crash. Keep in mind that you have access to counter inside the for loop.
To define a function with no parameters, write
To define a function with one parameter, write
To define a function with more than one parameter, write
The basic structure for an if-else statement is:
If booleanExpression1 is true, the first thing will be done and the second and third things will be skipped. If it is false and booleanExpression2 is true, the second thing will be done and the first and third will be skipped. If neither boolean expression is true, the third thing will be done and the first and second will be skipped.
To declare a variable, write
You only write var when declaring a variable. If value is a string, it must be in quotes.
A while loop is used to repeat a section of code over and over. Its basic syntax looks like this:
The code in the while loop will be executed as long as booleanExpression is true. If it never becomes false, the program will enter an infinite loop and crash. While loops can be used for doing things a certain number of times, but a better option in that case is often a for loop.
We've written many different pieces of code to allow your program to interact with the game and the dealer. You have access to the following functions:
You have access to the following boolean variables:
You have access to the following string variables:
You have access to the following arrays:
Every player tries to get a hand with a value of as close to, but no more than, 21 as possible. Face cards are worth 10 points, the Ace can be 1 or 11, and every other card is worth its face value. You play against a dealer. You and the dealer will each be dealt two cards at the beginning of the game. You will be able to see one of the dealer's. You will then have the option to "hit" (get another card) as many times as you'd like. Once you don't want any more cards, you "stand." Be careful! If the value of your cards exceeds 21, you "bust," that is, you lose! Once you stand, the dealer will draw cards. The dealer must hit if the total value of his/her cards is less than 17, and must stand if it is 17 or greater. When determining this, an Ace is counted as an 11. If the dealer busts and you don't, you win. If no one busts, whoever has a higher hand wins. If either player is initially dealt 21, that's a "Blackjack" and that player wins. If the players tie, the dealer wins (unless both players have Blackjack. Then it's just a tie.) If you get 5 cards without busting, you win. You bet at the very beginning of a hand, before you are dealt cards. If you lose the hand, the dealer takes your money. If you win, you get your money back and the dealer pays you as much as you bet. If you win with a Blackjack, the dealer pays you 150% of what you bet. You can also "double down." This means you double your bet and then only get one more card. You can only double down immediately after being dealt to; That is, you cannot hit and then double down. If you want more information, click here.