Credit Card Checker Challenge Project (JavaScript)

Hey guys, just completed the Credit Card Checker Challenge Project. Please see my code below:

Any feedback and/or constructive criticism is welcome. :slight_smile:

This response in particular had made it all makes sense to me. Thank you so much

Here is my final solution :innocent:

Hey, I just finished the credit card checker challenge project. If anyone has a bit of time at please can you look over it and give me any tips or pointers on things I could have done differently or better. Thanks

Hey guys, I just finished the credit card checker project. Could anyone give me some feedback on my solution :slight_smile: ? I had some trouble with the idInvalidCompanies function on line 101.
console.log(idInvalidCompanies([invalid1])) is logging Amex, Mastercard, Discover instead of Visa.
Thank you so much!

Your if statements are not nested corrected in the idInvalidCompanies function.
You have:

  invalidNumbers.forEach((number) => {
    if (number[0] === 4) {
    } else if (!companies.includes("Visa") ) {
      companies.push("Visa");
    }
    if (number[0] === 3) {
    } else if (!companies.includes("Amex") ) {
      companies.push("Amex");
    }
    if (number[0] === 5) {
    } else if (!companies.includes("Mastercard")) {
      companies.push("Mastercard");
    }
    if (number[0] === 6) {
    } else if (!companies.includes("Discover")) {
      companies.push("Discover");
    }
  });

but checking whether the array already includes stuff should be inside the other if-block.

  invalidNumbers.forEach((number) => {
    if (number[0] === 4) {
      if (!companies.includes("Visa") ) {
        companies.push("Visa");
      }
    }
    else if (number[0] === 3) {
      if (!companies.includes("Amex") ) {
        companies.push("Amex");
      }
    }
    else if (number[0] === 5) {
      if (!companies.includes("Mastercard")) {
        companies.push("Mastercard");
      }
    }
    else if (number[0] === 6) {
      if (!companies.includes("Discover")) {
        companies.push("Discover");
      }
    }
  });

HI All,

Here is a link to my credit card checker JS:

Hi, I just finished the Credit Card Checker challenge and here is my code.

Here is my attempt

Hello all,

Here is mine: GitHub - petsek/Credit-card-checker

Hi! Just finished after 3 days working on this project:

Hello to everbody,

Here is the link to my solution to this project.

Git Hub

I’ve also just finished mine: Codecademy export · GitHub

I’m not fully confident with Functional Programming yet, I’ll need to practice that more.
Any feedback is appreciated

Can someone explain the solution switch statement please. I don’t understand - if (companies.indexOf(‘Amex’) === -1).

Thanks

function idInvalidCardCompanies(invalidBatch) {
const companies = ;
for (let i = 0; i < invalidBatch.length; i++) {
switch (invalidBatch[i][0]) {
case 3:
if (companies.indexOf(‘Amex’) === -1) {
companies.push(‘Amex’);
}
break
case 4:
if (companies.indexOf(‘Visa’) === -1) {
companies.push(‘Visa’);
}
break
case 5:
if (companies.indexOf(‘Mastercard’) === -1) {
companies.push(‘Mastercard’);
}
break
case 6:
if (companies.indexOf(‘Discover’) === -1) {
companies.push(‘Discover’);
}
break
default:
console.log(‘Company not found’);
}
}
return companies;
}

Hi there,

Basically by using .indexOf(), we are trying to check if the ‘Amex’ is already part of array or not. If ‘Amex’ is not part of the array than indexOf() will return -1.

Let me know if it still is confusing.

Thanks,
S

Thank you for that. yes it makes sense.

And is this condition there to prevent duplicates? as per the instruction.

So if case 3 is met, but Amex is already in the array, it wont push Amex again.

Yup, you are right. This is to prevent duplication, so there is no double entry.

Thank you. I really appreciate your help.

Here’s my try at the Card Checker project. It took a lot of Googling and several tries. It’s not the prettiest thing looking at some of the other submissions but it did get the job done. Any suggestions would be appreciated.

https://github.com/msilis/creditCardChecker/blob/main/main.js