1to1k
1to1k

Reputation: 31

Two function returning a value which is used in third function

first = function firstFunction(arg1){
    return arg1;
}

second = function secondFunction(arg2){
    return arg2;
}

final = function secondFunction(first, second ){
    return first + second;
}

first(10);
second(20);

final(first, second);

I wrote this code and here's what I understand of it. Got three function first two return a value. first has the value it returned and second the same.

Now the third one is using two parameters, first and second. According to me first argument has value of 10 and second 20.

The third function is suppose to return first + second which is 30. But instead it returns this:

"function firstFunction(arg1){
    return arg1;
}function secondFunction(arg2){
    return arg2;
}"

Help, please

Upvotes: 0

Views: 253

Answers (2)

ishika
ishika

Reputation: 1

function One(arg1){
    return arg1;
}
function Two(arg2){
    return arg2;
}
function Three(arg1, arg2){
    return arg1 + arg2;
}

let first = One(5);
let second = Two(5);
console.log( Three(first , second) );

Upvotes: 0

Individumm
Individumm

Reputation: 183

You did not give the value as a parameter but you gave the functions itself. Try something like this:

final(first(10), second(20));

Another way to go:

var a = first(10);
var b = second(20);

final(a, b);

Upvotes: 1

Related Questions