Avatar of Temir Aliev
Temir Aliev
Flag for United States of America

asked on 

callback function

/*
Instructions

Write two functions, one called add and one called multiply, that each takes in two numbers and returns the appropriate new value.

Write a function called math that takes in two numbers, and a function 'operator' as parameters.
This function should return a callback invoked with the appropriate arguments.

*/

function add(num1, num2){
  return num1 + num2;
}

function multiply(num1, num2){
  return num1 * num2;
}

function math(num1, num2, callback){
  if(callback == "add"){
     add();
  } else if( callback == "multiply"){
     multiply();
  }
}

console.log(math(2, 5, 'add'))

Open in new window




//WHY IS MY CALLBACK NOT WORKING?
JavaScript

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon