Home > Blockchain >  Functions, how to call them 3 differente times, with different value
Functions, how to call them 3 differente times, with different value

Time:12-10

I´m stuck in this exercise, it seems simple, but I tried to use some of examples that they provide me, but none worked.

They declare me a function:

var double = function (x) {
    console.log(x * 2);
};

Now they ask me call it three times, each time with a different value and say that "You'll need to use the name we've given to the variable, followed by a number inside a pair of parenthesis."

Being trying to construct this lines based on some examples that I search online, but nothing seems to work, I think I´m not calling the fucntion the right way, can you help me and also provide some lights? Also please dont jugde my question, I´m new at this and trying my best to learn!

Thanks

UPDATE : RESOLVED Thanks!

CodePudding user response:

You need to follow the instructions and do exactly what it tells you.

It doesn't say to declare any variables. So why do you have let x = ....

It doesn't say to use the function keyword, so why have you?

Do exactly what it says.

Take the name they have given to the function (i.e. double) followed by the number (5) inside a pair of parenthesis (( and )).

double(5)

and do that three times

var double = function(x) {
  console.log(x * 2);
};

double(5)
double(10)
double(100)

CodePudding user response:

I would say just call your function:

var double = function (x) {
    console.log(x * 2);
};
double(1);
double(2);
double(3);

or

var double = function (x) {
    console.log(x * 2);
};
for(let i=0; i < 2; i  ){
    double(i);
}

CodePudding user response:

try

    function returnDouble(val){
        var mult = val*2;
        return mult;
    }
    

and them type

returnDouble(2)
  • Related