22/*main function is getting the info from other functions and returns the errors of the
33invalid card number or returns the statement that says card number is valid.*/
44function main ( cardNum ) {
5- // let errors = [];
65 if ( isValid ( cardNum ) === false ) {
76 console . log ( `(${ cardNum } )` )
87 if ( checkLength ( cardNum ) === false ) {
@@ -39,15 +38,17 @@ function checkLength(cardNum) {
3938function checkSum ( cardNum ) {
4039 let sum = 0 ;
4140 for ( let i = 0 ; i < cardNum . length ; i ++ ) {
42- sum = parseInt ( sum ) + parseInt ( cardNum [ i ] ) ;
41+ sum = sum + parseInt ( cardNum [ i ] ) ;
4342 }
4443 if ( sum > 16 ) {
4544 return true ;
4645 }
4746 return false ;
4847}
4948
50- // checking the card number if it has at least 2 different numbers
49+ /* checking the card number if it has at least 2 different numbers
50+ .split() method and every() method takes each character of the string into an array
51+ then the function checks all the characters if they match with the first one, returns true if all characters same*/
5152function allEqualCharacters ( cardNum ) {
5253 let characterCheck = cardNum . split ( '' ) . every ( char => char === cardNum [ 0 ] ) ;
5354 if ( characterCheck == true ) {
@@ -65,9 +66,11 @@ function isEndEven(cardNum) {
6566 return false ;
6667}
6768
68- // checking if the card number is made of only numbers
69+ /* checking if the card number is made of only numbers
70+ ^ does a match for the first character of the string
71+ \d searches for the digits between 0-9*/
6972function onlyNumbers ( cardNum ) {
70- let isNumOnly = / ^ \d + $ / . test ( cardNum ) ; //this method is to check if the items of the variable is only made of numbers if so it returns 'true'.
73+ let isNumOnly = / ^ \d + $ / . test ( cardNum ) ;
7174 if ( isNumOnly == true ) {
7275 return true ;
7376 }
@@ -95,11 +98,10 @@ function isValid(cardNum) {
9598}
9699
97100
98- //main('1000000000006');
99101main ( '9999777788880000' ) ; //valid number example
100102main ( '6666666666661666' ) ; //valid number example
101103
102104main ( 'a92332119c011112' ) ; //Invalid number example
103105main ( '4444444444444444' ) ; //Invalid number example
104106main ( '1111111111111110' ) ; //Invalid number example
105- main ( '6666666666666661' ) ; //Invalid number example
107+ main ( '6666666666666661' ) ; //Invalid number example
0 commit comments