Here is my solution! Feedback would be appreciated.
https://github.com/duomaz49/CreditCardCheckerJS/blob/master/CreditCardChecker.js
Here’s mine too
Further challenges added:
Hello, here is my solution to the code on my Github. Was a super tough project imo, I felt a bit overwhelmed but I broke down each section bit by bit which made it easier and more logical to follow as I was doing it.
Hi everyone! Here is my repo for credit card checker problem. I only added the second function from the challenging part that is to convert a string into an array of numbers. I appreciate for any comments or suggestions.
GitHub: credit_card_checker/cardChecker.js at main · hazalonler/credit_card_checker · GitHub
Hi everyone,
Why is idInvalidCardCompanies(findInvalidCards(batch)) printing one output?? Should it be printing more companies’ names as output for the list in findInvalidCards?
This is my code:
Hello guys
This is my solution of this project. Yes, it was tough to put everything together, remember what rules to use, what new can I add
It still kills me how people are so gravitated to reversing the array when it is not necessary. The parity of the length is what determines the doubling points, given the starting point. Can’t say how disappointing this is to see so ooo many posts that implement reversing the array. It’s just cringe worthy. People are so bought into this that they fail to explore other possibilities, or exhibit any sort of skepticism, whatever. I grieve at that very notion.
Here is my solution code:
// 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]
const valids = [valid1, valid2, valid3, valid4, valid5]
// 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]
const invalids = [invalid1, invalid2, invalid3, invalid4, invalid5]
// 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]
const mysteries = [mystery1, mystery2, mystery3, mystery4, mystery5]
// 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(cardNumber) {
let sumArray = ;
let totalSum = 0;
for (let i = cardNumber.length - 2; i >= 0; i -= 2) {
let doubledDigit = cardNumber[i] * 2;
sumArray.push(doubledDigit > 9 ? doubledDigit - 9 : doubledDigit);
}
for (let i = cardNumber.length - 1; i >= 0; i -= 2) {
sumArray.push(cardNumber[i]);
}
for (let i = 0; i < sumArray.length; i++) {
totalSum += sumArray[i];
}
return totalSum % 10 === 0;
}
function findInvalidCards(creditCardArray) {
let invalidCards = creditCardArray.filter(digits => validateCred(digits) !== true)
return invalidCards;
}
function idInvalidCardCompanies(arrayOfInvalids) {
let companyArray = ;
for (let i = 0; i < arrayOfInvalids.length; i++) {
if (arrayOfInvalids[i][0] === 3) {
companyArray.push('Amex');
} else if (arrayOfInvalids[i][0] === 4) {
companyArray.push('Visa');
} else if (arrayOfInvalids[i][0] === 5) {
companyArray.push('Mastercard');
} else if (arrayOfInvalids[i][0] === 6) {
companyArray.push('Discover');
} else {
companyArray.push('Company not found');
}
}
function removeDuplicates(array) {
return array.filter((value, index) => array.indexOf(value) === index);
}
return removeDuplicates(companyArray);
}
I like your solution in doubling the even numbers, awesome job!
I appreciate it! I had fun with this one. I’m still learning, so this one wasn’t too hard, but it also wasn’t too easy. It was just right.
My repository.
Took almost all day, but I have to say I feel pretty good being able to figure this out. thanks to @catvenom for responding to my frustration post. Helped me change the mindset I was stuck in and pushed through.
Check out what I did and let me know your honest thoughts. Can’t get better without an honest code review…just keep in mind I am an absolute n00b /lol
Here is my code for the project:
https://www.codecademy.com/workspaces/65bd2e8d8381df04d2ada9a6
Hey there! I tackled this project with a unique approach, going through it step by step, and everything’s running smoothly. Feel free to take a look at my solution here: ChallengeProjectCreditCardChecker.js (github.com).
Hello everyone. I share with you my project finished. I hope you guys can give me some retro if you find something.
If I were to undergo the same experiences as you, I wouldn’t voice any complaints. For beginners, there’s a substantial amount to absorb, so it’s unfair to place blame on them or us for adopting the method.
Hi there, I’ve reviewed your code. In the function call idInvalidCardCompanies()
, you’re checking if the array includes a specific word. However, if you declare the array as empty, it will always remain empty. In this scenario, the statement doesn’t seem to make sense since you’re passing the word even when the array is empty.