Credit Card Checker Challenge Project (JavaScript)

This is my attempt on the project CREDIT CARD CHECKER

Any suggestion is highly appreciated. Thanks

hey guys if you enjoy check that out … I just finished All the code are commented – CRED CARD CHECKER

Here is my GitHub contribution

Let me know if its okay!

Wow, this challenge was really brain boggling for me, but I think I did it!

Here’s the link to my code if anyone would like to review it an offer suggestions, I’m all ears!

Nothing new but i just did it.

GitHub

Here is mine y’all! I had a tough time on this project but we love a challenge:

Here is my code, any suggestion on optimize the code would be appreciated :smiling_face_with_three_hearts:

Hello everyone :smiling_face:,
That’s my solution(The idinvalidcompanies side could be edited a bit more but I was exhausted :grin: ):

// All valid credit card numbers
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]
const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9]
const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6]
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5]
const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6]

// All invalid credit card numbers
const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]
const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3]
const invalid3 = [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4]
const invalid4 = [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5]
const invalid5 = [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4]

// Can be either valid or invalid
const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4]
const mystery2 = [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9]
const mystery3 = [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3]
const mystery4 = [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3]
const mystery5 = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3]

// An array of all the arrays above
const batch = [valid1, valid2, valid3, valid4, valid5, invalid1, invalid2, invalid3, invalid4, invalid5, mystery1, mystery2, mystery3, mystery4, mystery5];

// Add your functions below:

function validateCred(array) {

let newArray = [...array];
let poppedNums = 0;
for (let i = 0; i < array.length; i++) {
    let num = newArray.pop();
    if (i % 2 === 1 ) {
        num *= 2;
        if (num > 9) { 
            num -= 9;
        };
    }; 
    poppedNums += num;
}
return poppedNums % 10 === 0;

};

console.log(validateCred(valid1));

function findInvalidCards(array) {
let invalidArray = ;
for (let i = 0; i < array.length; i++) {
if(!validateCred(array[i])) {
invalidArray.push(array[i])
}
}
return invalidArray;
}

function idInvalidCardCompanies (array) {
let resultArray = ;
for (let i = 0; i < array.length; i++) {
if(array[i][0] === 3) {
if(!resultArray.includes(‘Amex (American Express)’)) {
resultArray.push(‘Amex (American Express)’);
}
resultArray.push(array[i]);
continue;
} else if (array[i][0] === 4) {
if(!resultArray.includes(‘Visa’)) {
resultArray.push(‘Visa’);
};
resultArray.push(array[i]);
continue;
}else if (array[i][0] === 5) {
if (!resultArray.includes(‘Mastercard’)) {
resultArray.push(‘Mastercard’);
};
resultArray.push(array[i]);

  continue;
}else if (array[i][0] === 6) {
  if (!resultArray.includes('Discover')) {
    resultArray.push('Discover');
    };
  resultArray.push(array[i]);

  continue;
} else {
  resultArray.push('Company not found');
  resultArray.push(array[i]);
}}

return resultArray;
}

console.log(idInvalidCardCompanies([[4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5], [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4],[6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5], [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4] ]))

YouTube is one of the most popular platforms for sharing video content, and growing your audience requires strategic effort. Here are some actionable tips to help you increase views on your YouTube channel.

Here is my solution!

here is my solution guys:

Hello Devs, here is my final code, I tested it, it seems good to go, however, I am not sure 100%, i don’t how i can be sure, also i want to share that i did use help to AI tools little bit for reach the final solution, I not sure if that is good to help me learning or it will kind of block my mind of thinking like a programmer, even though i didn’t rely 100% on AI.

Credit Card Checker Challenge

My snippet below!

https://gist.github.com/sentinelity/b2aff04fac9b7af2d5a435c04e602b7a

Hey devs, here’s my code any recommendations are welcome ! creditcardchecker.github.io/creditCardChecker at main · darkgonzpe/creditcardchecker.github.io · GitHub

Here’s my go at it. After looking at the solution code, I’ll say that it probably runs a tad more efficiently than mine, but we’re still learning here, so I don’t think that’s a problem for now. Credit-Card-Checker/credit-card-checker.js at main · Flurmos/Credit-Card-Checker · GitHub

Hi, all good?

Here is my solution: GitHub - guilhermegorgen/creditcardchekerchallange: Codecademy Challenge Project: Credit Card Checker

Thanks!

Hi guys, this is my solution using reduceRight to check the card validation so the accumulator would hold the sum value and checking the odd and even from the last using current index.

Feel free to contact me, so we can discuss about the future project together, thank you :blush:

This project was so much fun! here’s my code!

git: GitHub - eliazar-lopez/Credit_Card_Checker: JavaScript project using Luhn's algorithm to validate a credit card number. Has functions to determine whether a number is valid or not and lists companies with invalid card companies. There is also a function that takes in a string that is placed in a list to validate.

I just finished this project and i would love to hear some improvements you guys may suggest on my code!
https://github.com/Yagotrindade/creditCardChecker.git

I don’t know if previous projects had the options to share your code via the forums; however, glad to finally get my feet wet diving into this career path! This was a little tricky and it’s cool how a lot of us followed similar idea paths, but had different ways to tackle the project!

// All valid credit card numbers const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]; const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9]; const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6]; const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5]; const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6]; // All invalid credit card numbers const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]; const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3]; const invalid3 = [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4]; const invalid4 = [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5]; const invalid5 = [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4]; // Can be either valid or invalid const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4]; const mystery2 = [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9]; const mystery3 = [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3]; const mystery4 = [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3]; const mystery5 = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3]; // An array of all the arrays above const batch = [ valid1, valid2, valid3, valid4, valid5, invalid1, invalid2, invalid3, invalid4, invalid5, mystery1, mystery2, mystery3, mystery4, mystery5, ]; // Add your functions below: const validateCred = (arr) => { // Luhn algorithm to validate the credit card let total = 0; // Check to ensure only 16 if (arr.length < 16) { return false; } else if (arr.length > 16) { return false; } else { // Step 1 -> checking digits from the right (i.e. reverse the arry) let check1 = [...arr].reverse(); // Step 2 -> let check2 = []; const mathCheck = (num) => { let check = num * 2; if (check > 9) { return check - 9; } else { return check; } }; for (let i = 0; i < check1.length; i++) { if (i % 2 === 0) { check2.push(check1[i]); } else if (i % 2 !== 0) { check2.push(mathCheck(check1[i])); } } // Step 3 -> total = check2.reduce( (accumulator, currentValue) => accumulator + currentValue, 0 ); // return true or false return total % 10 != 0 ? false : true; } }; const findInvalidCards = (arr) => { let invalidArray = []; arr.forEach((card) => { if (!validateCred(card)) { invalidArray.push(card); } }); return invalidArray; }; const idInvalidCardCompanies = (arr) => { let companyArray = { Amex: 0, Visa: 0, Mastercard: 0, Discover: 0, Unknown: 0, }; arr.forEach((card) => { switch (card[0]) { case 3: companyArray.Amex++; break; case 4: companyArray.Visa++; break; case 5: companyArray.Mastercard++; break; case 6: companyArray.Discover++; break; default: companyArray.Unknown++; break; } }); return companyArray; }; console.log(validateCred(valid1)); console.log(findInvalidCards(batch)); console.log(idInvalidCardCompanies(findInvalidCards(batch)));