A22.0005 - Spring 1999
Assignment # 3

Due: Thursday, March 11th

Projects should be turned in two ways:

1) Posted on your acf5 Web account under the name "assign3.html"

2) Put on a single 3 1/2" floppy disk, and turned in with complete, COMMENTED listings in an envelope.

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. 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 colours 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. (Actually, the number of hands which have been dealt since the last time "Blackjack" was dealt, since, as we will see below, the JavaScript program will be restarted each time "Blackjack" occurs.) Note again, that it IS possible for the same two cards to be picked!

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 youproceed to total the points for the hand, however, remember the problem of having two aces!)

Part B. Each time "Blackjack" is dealt, you should PAUSE for 3 seconds, and then proceed to a different HTML file, where you will provide a brief celebratory GIF animation. At the conclusion of that animation, the JavaScript should return you to the original screen.

(Hint on JavaScript: Since you will be both setting variables and checking them, remember that "=" is used to set the value of a variable, while "==" is used in an IF statement to check its value!)

Note that although this assignment is Due on Thursday, March 11th, the Midterm is on Tuesday, March 9th. You should have mostly finished it by the time of the midterm.