Can Anyone help me write this in java script

Exercise One: In this exercise you will be creating two functions.

// Function One: Will be called 'multiply'.

// This function will take two parameters, both numbers

// This function will return the two numbers multiplied together.

// Function Two: Will be called 'calculator'.

// This function will take three parameters,

// First will be a callback function,

// Second and Third will be numbers.

// This function will return the two numbers passed into the callback function.

// NOTE: You can use the multiply function to test the calculator function, but understand that

// other callback functions will be passed into it as a test.

What part of these functions do you need help writing?

@mwilki7 function 2

@faziz6006

Function 2 will look something like:

"First" is going to be the name of a function passed as a parameter to "secondFunction()"

Next you just need a return statement before you call "First(...)" with Second and Third as parameters being passed to First

@mwilki7 im lost lol

function secondFunc( wait where did u get the second function from?

@mwilki7

function calculater ( call back function, 1, 2) ?

@mwilki7 im so overwhelmed plez help

@faziz6006

secondFunc() is just the name I chose to call Function 2, now I see it's supposed to be called "calculator"

Here it is with more helpful variable names:

@mwilki7 ok so ..

function calculator (callback (I thought this was a function, or is this funcation called a callback?), 1, 3);

@faziz6006

calculator is a function

callback is also a function

you can pass functions as parameters and call them later like so:

@mwilki7 oh, so so then i just return the two numbers passed into the callback?

so my answer is :

function calculator (callback, 1, 2)

{

callback(1, 2)

}

return (1, 2) ;

@mwilki7 I think i need to go back and study javacript from the beginning again. its just that this course work is due and i dont get why they gave me work before i even started learning java script,

@faziz6006

JavaScript doesn't allow numbers to be names of variables

try instead:

or whatever name you think fits the 2nd and 3rd parameters.

You almost had it, just put the return statement inside the brackets like so:

The return statement

@mwilki7 oh, but didint it say the function will take three parameters and two will be numbers? but ok i will call it p1 and p2

so here is the final answer?

function calculator (callback, p1, p2)

{

callback (p1, p2)

return callback(p1, p2)

}

@faziz6006

Somewhere in the program someone will call

calculate(...)

They are responsible for putting numbers in the parameters:

When we create the function, we use variables for parameters.

For this case, p1 and p2 must be treated like numbers otherwise program may throw errors.

@mwilki7

you lost me, im sorry , any chance u can give the answer so i can submit it, then im going start the video from the beginning and try to figure out where i got lost.

@faziz6006 Your answer above my previous post should work.

@mwilki7 there is a error saying :

ReferenceError: multiply is not defined

"Should return the two numbers passed into the callback function"

@faziz6006

Did you insert this one?

@mwilki7 yes maybe im not writing it in the right space: here is the full question , where should i write my answer? and what does the last sentence ask me to do ?

// Exercise One: In this exercise you will be creating two functions.

// Function One: Will be called 'multiply'.

// This function will take two parameters, both numbers

// This function will return the two numbers multiplied together.

// Function Two: Will be called 'calculator'.

// This function will take three parameters,

// First will be a callback function,

// Second and Third will be numbers.

// This function will return the two numbers passed into the callback function.

// NOTE: You can use the multiply function to test the calculator function, but understand that

// other callback functions will be passed into it as a test.

function calculator (callback, p1, p2)

{

callback (p1, p2);

return callback(p1, p2);

}

//Call MULTIPLY to multiply the two numbers

var product=MULTIPLY(number1, number2);

@mwilki7 same error msg?

@faziz6006

Looks like the multiply function is missing:

@mwilki7 gosh, thanks for bearing with me, any tools u suggest so i can start java scrpt from beinging , im like brand new to this

@faziz6006 JavaScript programming tutorials on youtube may be a good start.

If you want some place to practice it, try opening nodejs projects on repl (that way you don't need to know HTML).

Try coming up with little programs that sound fun to make, and if there's anything you don't know google it.

Most of my own code is just snippets of what I found online.

@faziz6006 Hey, I think you might need a refresher on how functions actually work. Give this shamelessly advertised answer of mine a read and let me know whether it helps.