V22.0005 - Spring 2004
Assignment # 3

Due: Thursday, Feb. 26th

Projects should be posted on your I5 Web account under the name "assign3.html"

Be sure to email pnp2@cs.nyu.edu to turn in your assignment.

New: Here are some cards to help you out - if you haven't already designed your own!

You are to write a JavaScript program which will deal a two card hand of Blackjack, and total the points for that hand. Cards are totaled as follows: A card with a face value of 2 through 10, counts the same number of points, 2 through 10. A Jack, Queen or King counts 10 points. Finally, an Ace counts as 11 points, unless there are two of them in a single hand, in which case one of them counts as 1 point only, making the entire hand of two Aces equal to 12 points. Note that a winning hand, or "Blackjack", is a hand that totals 21 points, i.e., a hand that has one Ace and either a 10, a Jack, a Queen or a King.

Part A. By checking a cookie, see if anyone has ever played this game of Blackjack on this machine. If not, ask them their name. If they have, greet them by name and tell them how many "Blackjacks" they have gotten in total so far. (Hint: Get this part to work after you have the other parts up and running!)

Part B. Using the supplied gif files of the 13 cards and an additional file representing the back of a card, write a JavaScript program (again, based upon the dice game) which will randomly select two cards and put them on the screen. (To make the game simpler, I have only supplied one suit of cards, the Hearts). Each card is drawn completely randomly from the other. Thus, you might have two Aces of Hearts or two 8's in a single hand, as well as the possibility of having two cards which have different values.

When the screen is first seen, only the "backs "of the two cards are visible. Each time you press the on screen button, two more cards are dealt. (By the way, your layout and colors do NOT have to match my example!)

Once you have dealt the two cards, in a FORM, you should print out the POINTS for each of the two cards, and the TOTAL POINTS for the hand. You should also keep a running count of the number of hands which have been dealt. Note again, that it IS possible for the same two cards to be picked! [Also add a counter which counts the number of identical pairs.]

Note that I have provided screenshots of my working example, since I couldn't actually post the solution...

(Hint on picking the card and finding its "points": I have carefully chosen the card names as being "2hearts.gif" through "14hearts.gif". Thus, you will choose a random number from 2 thorugh 14, and display the appropriate card. For cards 2 through 11, the POINTS will thus be equal to the hand number. Only for cards 12hearts.gif, 13hearts,gif and 14hearts.gif will this differ. For each of those three cards, the number of POINTS will be equal to 10. When you proceed to total the points for the hand, however, remember the problem of having two aces!)

Part C. Each time "Blackjack" is dealt, you should PAUSE for 2 seconds, and then open a NEW Window, where you will provide a brief celebratory GIF animation. At the conclusion of that animation, the JavaScript should pause. There should be a button in the window that when you push it will close the window and return you to the original screen.

For those Students who have Either 1) taken JavaScript before or 2) are Comp Sci majors (you know who you are), make certain that you deal 52 unique cards, and then display an Alert box that says "Redeal" which starts a new hand.