I was given a prompt to plete and this is what is says
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.
I have almost pleted the problem and am stuck as to what to do to finish, any help would be appreciated. This is what I have.
function add(num1, num2){
return num1 + num2;
}
function multiply(num1, num2){
return num1 * num2;
}
function math(num1, num2, func){
return func();
}
math(1,2,add);
I was given a prompt to plete and this is what is says
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.
I have almost pleted the problem and am stuck as to what to do to finish, any help would be appreciated. This is what I have.
function add(num1, num2){
return num1 + num2;
}
function multiply(num1, num2){
return num1 * num2;
}
function math(num1, num2, func){
return func();
}
math(1,2,add);
the log is only returning nan and i am not sure why it is not a number, I am also not sure if the code is written how they want with callbacks?
Share Improve this question edited Nov 27, 2017 at 5:05 Salomon Zhang 1,5653 gold badges23 silver badges42 bronze badges asked Nov 27, 2017 at 2:09 Devin BowenDevin Bowen 892 silver badges9 bronze badges 1- 1 Your function math(num1, num2, func){ return func(); } return function not gives any params – Salomon Zhang Commented Nov 27, 2017 at 2:24
1 Answer
Reset to default 7You should change math function to use num1 and num2 when you call func
function math(num1, num2, func){
return func(num1, num2);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744961519a4603414.html
评论列表(0条)