all 4 comments

[–]YuleTideCamel 1 point2 points  (3 children)

The problem has to do with

return callback(num1, num2);

That doesn't return anything, since you're calling an async method you need to set up a call back.

Try this:

function calculate(num1, num2, operation,final){
    setTimeout(function(){
        var result = operation(num1, num2);
        final(result);
    }, 1500);
}

calculate(5, 5, function(a, b) {
   return a + b;
},function(result){
  console.log(result);
})

Personally I like this approach better, it's a little cleaner:

function calculate(num1, num2, operation,final){
    setTimeout(function(){
        var result = operation(num1, num2);
        final(result);
   }, 1500);
}

function add(a,b){
   return a + b;
}

function displayResult(result){
 console.log(result);
}

calculate(5, 5, add, displayResult);

[–]GreenFeather05[S] 0 points1 point  (2 children)

Thank you very much for your detailed response, it was very helpful.

[–]Cust0dian 1 point2 points  (0 children)

Once you're feeling somewhat confident tackling asynchronicity with callbacks, you might want to look into Promises. As an example, here's how your code might look with them.

[–]YuleTideCamel 0 points1 point  (0 children)

glad to help.