Download the attached Zip file which can be loaded into Atom. The instructions are in the comments or text files associated with each exercise.
JS02.zip
Credit Card valid: Here are some formats of some well-known credit cards. •
American Express :- Starting with 34 or 37, length 15 digits. • Visa :- Starting
with 4, length 13 or 16 digits. • MasterCard :- Starting with 51 through 55,
length 16 digits. • Discover :- Starting with 6011, length 16 digits or starting
with 5, length 15 digits. • Diners Club :- Starting with 300 through 305, 36, or
38, length 14 digits. • JCB :- Starting with 2131 or 1800, length 15 digits or
starting with 35, length 16 digits.
Modify program to display a text box to enter a credit card number. Place a
button that say Validate CC. Make the button call a JavaScript function to
return the type of credit card if it is valid (i.e. AMEX, Visa) Otherwise print a
message into HTML saying “Invalid CC Number”. Use a nested if.. else structure
or case.. switch structure in JavaScript. The code given in the sample code is
for a generic test of any CC that matches any CC pattern.
Pull out specific patterns from the larger more complex pattern.
/ˆ(?: (4[0-9]{12}(?:[0-9]{3})?) |(5[1-5][0-9]{14}) |(6(?:011|5[0-9]{2})[0-9]{12})
|(3[47][0-9]{13}) |(3(?:0[0-5]|[68][0-9])[0-9]{11}) |((?:2131|1800|35[0-9]{3})[09]{11}) )$/;
Pull out the American Express reg expression. /ˆ(?:3[47][0-9]{13})$/
https://www.w3schools.com/jsref/jsref_obj_regexp.asp https://eloquentjavascript.net/09_regexp.html
1
function is_creditCard(str) { regexp = /ˆ(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][09]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[09]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/;
if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}
console.log(is_creditCard(“378282246310006”));
console.log(is_creditCard(“37828224630006”));
1
Recursion is a problem-solving technique that breaks a larger problem into smaller and smaller
parts until a smallest general case exists.
Write a JavaScript program to compute the exponent of a number using recursion. An HTML
document is given with two text fields to store the base number and the exponent. Past those
values into the JavaScript function that you will program.
Note: The exponent of a number says how many times the base number is used as a factor.
82 = 8 x 8 = 64. Here 8 is the base and 2 is the exponent.
power(base,exp)
Exponent or
power
Start
2
4 = 16
Base
===
0
Yes
No
Base number
Solution
Return 1
Return base x
power(base, exp -1)
4 X 4 = 16
STOP
V
16