1. (35 points) An HTML page must validate a user's credit card. The HTML page shown below has: (1) a form named aform; a 16 character textbox named acct; three radio buttons named cc; and a button labeled "Validate" that calls a sub named card when clicked.
Each credit card company uses a particular structure to create their credit card account numbers. For the three credit card types shown at the left, the following rules apply:
Credit Card
Account begins with the digits:
Number of characters in the account number
MasterCard
51, 52, 53 or 54
16
VISA
4
13 or 16
American Express
34 or 37
15
When the user enters an account number, chooses a credit card type and clicks the "Validate" button, a sub named card checks the two validation criteria: (1) the account prefix and (2) the account number length. If the account is invalid display either the message: "INVALID LENGTH" or "INVALID PREFIX" and exit the sub. Otherwise display the "ACCOUNT IS VALID" msgbox. Show only the VBbscript for card -- show NO HTML. DO not perform numeric tests on the acount number.
1
2
3
4
5
6
2. (50 points) Two 10 by 10 pixel image files are available: b.gif (this image shown with border="1") and w.gif (this image shown with border="1"). Assume an HTML page has been created with a single button with the label: "Roll the dice". Like this:
Click this button for the answer
Click "VIEW", then "SOURCE" to see the code
When this button is clicked, the javascript function named roll is executed.The program first generates two random numbers (between 0 and 1) and converts them each to a digit between 1 and 6 inclusive (i.e., 1,2,3,4,5, or 6). Based on these digits, two tables are created that present the image of the face of the dice for each digit. The six possible faces associated with each of the six possible digits are shown at the left.
The function creates these two tables by generating a new page on-the-fly. Each table contains three rows and three columns per row. The first table shows the image associated with the first random digit and the second table shows the image of the dice for the second random digit. The tables have border="0", cellspacing="0" and cellpadding="0" and the new page has the background color "#999999".
Each cell of the tables contains either the image b.gif or w.gif. For example, for the random digit five: the first row contains the image files: b.gif, then w.gif, then b.gif in the three cells; the second row contains: w.gif, then b.gif, then w.gif in the three cells; and the third row contains: b.gif, then w.gif, then b.gif in the three cells. To simplify your program, assume that an array named d has been defined and initialized as shown below (i.e., don't write this -- just use it):
var d = new Array (6)
d[0]="wwwwbwwww"; // for digit 1
d[1]="bwwwwwwwb"; // for digit 2
d[2]="bwwwbwwwb"; // for digit 3
d[3]="bwbwwwbwb"; // for digit 4
d[4]="bwbwbwbwb"; // for digit 5
d[5]="bwbbwbbwb"; // for digit 6
This array contains the sequence of the nine images as they should be presented in the table. The first three characters represent the images in the first row; characters 4 thru 6 represent the images in the second row, and characters 7 through 9 represent the images in the last row. A "b" means display the b.gif image and a "w" means display the w.gif image. Print the random digit following each table that was used to create the table. Show only the javascript for the roll function.
3. (15 points) In addition to the two validation rules in (1) above, there is also a particular rule regarding the values of the digits in a credit card number. A simple algorithm can be used for all three credit cards to assure that the card number is valid. The validation algorithm creates a "check digit sum" by:
(1) Start with check_digit_sum=0
(2) For every other digit beginning with the second digit from the right and moving to the left:
(1) take the digit and multiply it by 2 (call this result x).
(2) sum up the individual digits of x and call this result y (e.g., if the digit is 9, multiplying by two yields x=18,
then the summing the digits in x gives y = 1 + 8 = 9)
(3) add the result (i.e., y) to the check_digit_sum (3) For every other digit beginning with the first digit at the right and moving to the left,
add the digit to the check_digit_sum (i.e., y is just the digit)
(4) When all digits have been processed, examine the last digit of check_digit_sum, if it is a 0 (zero) then the account number is valid.
For example, if the account number is an American Express card 371541546451505 (this table is for explanation -- NOT produced as part of your answer):
Account Number
3
7
1
5
4
1
5
4
6
4
5
1
5
0
5
x (digit x 2)
14
10
2
8
8
2
0
y
3
+1+4
+1
+1+0
+4
+2
+5
+8
+6
+8
+5
+2
+5
+0
+5
= check_digit_sum = 60 (so the acct number is VALID)
For example, if the account number is a MasterCard 5136043272845633(this table is for explanation -- NOT produced as part of your answer):
Account Number
5
1
3
6
0
4
3
2
7
2
8
4
5
6
3
3
x (digit x 2)
10
6
0
6
14
16
10
6
y
1+0
+1
+6
+6
+0
+4
+6
+2
+1+4
+2
+1+6
+4
+1+0
+6
+6
+3
= check_digit_sum = 60 (so the acct number is VALID)
Show the VBscript code you would add to the answer in the first problem. Include the error display option "INVALID CHECK DIGIT SUM".