-3

I have two functions, One function name is funOne. Another function name is funTwo. Now I have done simple addition in funOne function and funTwo function. Now I am trying to pass these funOne and funTwo functions as arguments to another function but output is not coming. Please correct my code to get output.

function fun(funOne, funTwo) {
  return (funOne + funTwo)
  
  function funOne(a, b) {
    return (a + b)
  }

  funOne(1, 2)

  function funTwo(x, y) {
    return (x + y)
  }

  funTwo(3, 4)
}

console.log(fun)
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
Vamsi
  • 151
  • 1
  • 4
  • 11
  • 1
    You never call `fun` ? Also adding functions makes little sense, you might want to add the results of calling them? (`funOne(1, 2) + funTwo+3, 4)` ) – Jonas Wilms Oct 05 '19 at 10:19
  • Hi Jonas Wilms, I am very new to Javascript, so can you please correct my code I am not able to understand your comment Thank you. – Vamsi Oct 05 '19 at 10:35

1 Answers1

1

Is this how you want your result ?

function fun(funOne, funTwo) {
  return (funOne + funTwo)
}

function funOne(a, b) {
  return (a + b)
}

function funTwo(x, y) {
  return (x + y)
}

console.log(fun(funOne(1, 2),  funTwo(3, 4)))

1- Putting return as first staement will never execute your other lines.

2- If you log a method in console.log without calling () then it will print whole method

3- QUESTION HEADLINE doesn't makes sense. If that is what you are trying to learn then please look Pass a JavaScript function as parameter

Bilal Siddiqui
  • 3,579
  • 1
  • 13
  • 20