Credit Card Checker Challenge Project (JavaScript)

This is one small step for a programmer’s career, one giant step towards motivation.
Obviously not the most elegant solution, but it works :muscle:

1 Like

I need a total video walkthrough of this project because Im not understanding this one point. The moment I think I’ve solved an issue I’m immediately met with one after the other - and I’m not understanding the process and why things work they way they do. D:

I think validateCred is mutating the arrays you pass through it due to const ccnum = arr

Inside the loop, (ccnum[i] *= 2) mutates. The original array arr is modified directly.
This happens again at ccnum[i] -= 9

Hi All,
Just finished the Challenge Project: Credit Card Checker. I was a really good challenge and valuable learning.
Definitely not the most effective solution, any advice is appreciated.

Instead of
const ccnum = arr;
Use this
const ccnum = arr.slice(0);

My solution :3 any suggestions on how to improve it will we highly appreciated

And here I thought I could escape math! :rofl:

But this was an enjoyable problem-solving, indeed. Whenever I start to work on this project, hours seem to pass so fast. I also find it challenging to break off on this for a while because I can’t stop thinking of how to solve this project haha

I did the project extension, wherein I could input a number and use the same function from the original requirements of the project. I also added the credit card number generator (this one was challenging), which generates a valid card number.

Feel free to check on how I did it here.

Ok, here is my solution to this project:

Any feedback, good or bad, would be much appreciated! I really enjoyed completing this project and I look forward to browsing other people’s solutions as well.

Here’s my solution:


When I first saw your code for the card digit sum calculator my head spun and I thought there was no way that works. I am not very good with using the ternary operators and I did not follow your logic. However, once I copied it, studied how it worked, and ran it in Node.js I am very impressed. I definately need to practice using ternary operators after seeing your work. Thanks!


I’m sorry to be the bearer of bad news, but your code does not work. This portion of your validateCred function is missing some logic:

for (let i = arr.length -1; i >=0; i–) {
if (i % 2 == 0) {
arr[i] = arr[i] * 2;
if (arr[i] > 9) {
arr[i] = arr[i] - 9;

If you are going to count your loop down from length-1 then you have to account for whether or not there are an even or odd number of digits in the card number. If you do not account for this then you will be doubling the wrong digit sometimes. Here is some code I made to verify the functions work properly. Feel free to paste it at the end of your code to check things out.

// calling functions for testing

// test all cards in batch array
console.log(‘\n\nTesting all cards in batch array’)
for (const card of batch) {
if (validateCred(card) == true) {
console.log(card.join(‘’) + ’ is valid’);
} else {
console.log(card.join(‘’) + ’ is invalid’);

// display all invalid card nums
console.log(‘\n\nThese card numbers are invalid’)
for (const card of findInvalidCards(batch)) {

// display card companies who issued bad cards
console.log(“\n\nThese credit card companies issued bad card numbers:”)
console.log(idInvalidCardCompanies(findInvalidCards(batch)).join(', '));

This is what the output of that code should be:

$ node main.js

Testing all cards in batch array
4539677908016808 is valid
5535766768751439 is valid
371612019985236 is valid
6011144340682905 is valid
4539404967869666 is valid
4532778771091795 is invalid
5795593392134643 is invalid
375796084459914 is invalid
6011127961777935 is invalid
5382019772883854 is invalid
344801968305414 is invalid
5466100861620239 is valid
6011377020962656203 is invalid
4929877169217093 is invalid
4913540463072523 is valid

These card numbers are invalid

These credit card companies issued bad card numbers:
Visa, Mastercard, Amex (American Express), Discover

Thank you very much for posting!
Loved the way you chained the ternary operator and how you used the new Set =)
Just one thing, the function validateCred(array) seems to only work properly for even length cards?

1 Like

Thanks, I’ll fix that

Hi, this is my solution : GitHub - Sonfresh/Challenge-Project-Credit-Card-Checker at 6fc1227e41741e51d7503efda6cf9f2f20083c6f

Hola con todos, esta es mi solución al Verificador de Tarjetas, espero les ayude :raised_hand:t3: :smiley:

I’ve enjoyed this challenge!
Feel free to take a look at how I implemented the main (and optional) tasks here:

here is my solution guys any feedback is welcome

Hi all!
here is my solution for this challenge. I did the opening task also.
Feel free to comment. thank you!

Done. Do feedback if there’s anything I can improve on! Thanks!


Here is my solution :

Thank you for your feedbacks !