Javascript Credit Card Checker - Set parameter as a function return

https://www.codecademy.com/practice/projects/credit-card-checker

Hello,

I’m in the step #5 of the project. And I don’t have very clear how to handle this…
“… Create a function, idInvalidCardCompanies() that has one parameter for a nested array of invalid numbers and returns an array of companies. …”

The parameter is the result of the findInvalidCards() function, so how can I add the result of a function into the parameters of another function.

Thanks,

When you call a function you can pass values to it:

add(3, 5)

and you get something back

result = add(3, 5)

which you’re free to use however you like

add(result, 4)

Thanks for you reply, I understand I can pass values as parameters. But, how can I pass the result (return) of a function to the parameters?

I showed you that, did I not?

I called add.
bound a variable to the result
passed the result back into add - what add returned is now an argument to add

Are you sure you’re not inventing something that doesn’t exist, or even expecting something to exist but you’re not sure what in which case … ???

A function accepts input, and produces output.
That’s pretty much the only thing going on.

So if you want to use the result of one function as input to another, then call the first one, get the result, call the second one with the result as one of the arguments

Ok, I understand better with the explanation you gave me. I need to store in a variable the result of the function, then pass it as parameter.

I was thinking about calling a function in another function parameters, like this:

function first() {
    return whatever;
}

function second(first()) {
    return anotherThing;
}

what would that accomplish? does that make sense? what are parameters, does that in some way match what you’re attempting to do?

Maybe your function should call a different function.

function first() {
    return whatever;
}

function second() {
    first();
    return anotherThing;
}

or maybe the caller of the first function should pass the result to the second

second(first())

variables are not storage, and you do not need a variable

if you have a value you can do further operations with it

second(first())  // no reason you'd need a variable to hold on to the result

An example of how variables are not storage is if you have two variables referring to the same thing:

let a = []
let b = a

which one is storing the array? neither, that’s not what variables do. variables are names that you can use to refer to values, the values already exist, storage has already happened or you wouldn’t have a value at all

if you look at this expression:

1 + 1 + 1

Note that the result from the first addition is used in the second, no variables were involved

1 Like

You can give a parameter a default value:

function f(x=1) {
}

You would specify a name for the parameter, and an expression for the value. Here the expression is 1.
You could use a different expression, you could for example call a function there:

function g() {
    return 3
}
function f(x=g()) {
    return x + 1
}

console.log(f())

But I think that’s a bit questionable, the effect of that is the same as this:

function g() {
    return 3
}
function f(x) {
    if (x === undefined) {
        x = g()
    }
    return x + 1
}

console.log(f())

Which is far more clear about what’s happening and what’s meant.

In any case, I don’t think your project has much use for default parameters…?

Per your description:

Your function is supposed to accept one argument. No mention of default values.

1 Like

Thanks for the info, it makes more sense.