Credit Card Checker Challenge Project (JavaScript)

Congratulations on completing your project!

Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.

This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!

About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines


How do I share my own solutions?

  • If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
  • If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.

Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:

  1. Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
  2. It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.

Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.

Best practices for asking questions about the sample solution

  • Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.
24 Likes

Hi, I am trying to download your solution to compare mine, but the link in this just takes me back to the credit_card_checker_starter that only has the code at the beginning of the project. Can someone please just send me the solution or update your link?

Thanks so much for finding that! We’ve updated the link above, and here it is as well: https://codecademy-content.s3.amazonaws.com/PRO/independent-practice-projects/credit-card-checker/credit-card-checker-solution.zip

1 Like

Hello, how can I see other students solutions?

And, where can I share my GitHub url?
Can you give me feedback on my solution?

Thanks

5 Likes

Hi,

I have changed the card checker as i wanted it to cycle through the arrays by using a function instead of a predefined array.
For the moment it’s using eval() but for obvious reasons I want another solution.

I am also having a bit of trouble not producing duplicates of the companies with mistakes.
here is the link:


Any help would be appreciated.
How can i make it better?

thanks

4 Likes

I have fixed the duplicate issue

1 Like

Hey guys! I am really stumped with this challenge project but I am trying to understand at my own pace. I got the first line of code for the project but had to refer to the sample solution for help. Can someone please walk me through what line 31 in the sample solution is doing.

(array.length - 1 - i) % 2 === 1)

I understand generically that this line of code is helping us pick out the lines of code that are every other so we can then multiply them by two for the Luhn formula but for some reason I can’t see the way the math works in my head.

Sorry to request such a detailed description but I have now spent like two hours just staring at this problem.

12 Likes

Cheers! Cool seeing all the different ways people got to the same answer.

1 Like

This was pretty tough, here’s my solution.

1 Like

That is my solution for this task lads. Everything is working fine!! Cheers

5 Likes

Does anyone see what’s wrong with my function? It counts all the stuff but filters the arrays that differ from the ones in the solution. Thank you.

function validateCred(anArray) {
let counter = ;
let i = anArray.length - 1;
do {
counter.unshift(anArray[i]);
i–;
if (i >= 0) {
anArray[i] *= 2;
anArray[i] > 9 ? counter.unshift(anArray[i] - 9) : counter.unshift(anArray[i]);
i–;
};
} while (i >= 0);
const reducer = (accumulator, currentValue) => accumulator + currentValue;
counter = counter.reduce(reducer);
return counter % 10 === 0;
};

Here’s my solution!

2 Likes

Just finished this. Here’s my solution.

1 Like

Hi, legoghetto!
I don’t see any problem with your solution. It seems perfectly functional.

Yeah, thanks. As I said it’s functioning but does filter wrong arrays. If you compare the output of this code and the solution code, you’ll see what I mean.

Does anyone know how to do the extension part of this project? I am not able to understand the parseInt() function and how can I use it in this case.

1 Like

I need to clean up my code a little but I got mine done. I think my validate function is a bit more simplistic than some others I have seen. https://gist.github.com/35d9e2fc971eeed70b3f28d26b648dc3

Hello everyone,

I finished this amazing project, this is my code, it works well.

Happy coding

Hi roubz1,

parseInt() is not complicated, I’m sure the following example can help you to understand better it:

let num = ‘36’;
console.log(typeof num); // Print “string”
num = parseInt(num);
console.log(typeof num); // Print “number”

2 Likes

Gosh this took me a few days to figure out.

8 Likes