Need help with Credit card checker step 4


I am stuck at step 4 of the credit card checker project (

My code is below with a couple comments on what I am seeing as output. I suspect something is incorrect in my control flow but I am not sure what.

const invalidCards = [];

const findInvalidCards = array1 => {
	for (i = 0; i < array1.length; i++){
    if (validateCred(array1[i]) === false) {

// console.log(validateCred(batch[0]));  returns true

// console.log(findInvalidCards(batch));  doesn’t log anything to the console, no error messages either.

usually a function creates some kind of result
If you for example have a function add then you’d call it with two numbers say 2 and 5 and get 7 back why would you get 7 back? because the function would hand that result back to the caller, that’s its whole job

Does the invalidCards.push not count as a result?

Also, does the function itself require a result of the purpose of it is to run something through a loop (example this function runs the credit card numbers through a loop, outputting the invalid ones to a new array, or at least that’s what it’s supposed to do).

Try writing a function that adds two numbers.

Where does the result go?

// should be able to get 7 to print to screen
console.log(add(2, 5))

I’m making the argument here that this is a basic feature of functions. Agree? (functions accept input and produce output) Maybe you’re either able to write a basic function that does the right thing and then do it with your other function as well, or you completely missed something when introducing yourself to functions, but that’s useful too because then you have an idea of where to find the missing information, and indeed you know what you’re looking for too.

I’m not sure how to understand what you’re saying. In the example you’ve provided, you haven’t defined the function yet so there is no output. If you’re trying to compare that to my formula, I’m not sure what you are getting at as my formula is defined, but is not returning what I’m expecting.

I understand how the function should work, I have done tons of them (in fact the trouble I had on the previous step was that I forgot to instruct the function to return the result instead of simply calculating it).

What I’m trying to get help with is why when I run the code (using the batch array as input) why the output is not the invalidCards array having the array at the given index of batch pushed to it.

Your problem is that your function has no output.

You could approach that problem by making a simple function that has an output. When you have such a function, then you have solved the problem, and can now solve it for your other function by doing it the same way there.
By viewing the problem in a simpler environment you rule out a whole bunch of other possible causes, allowing you to look only at the relevant parts of your problem, making it easier to focus in on the cause.