Homework on Functions - Questions

  1. A function describes how a certain mathematical calculation is working out. It consists of an income and an outcome. The income, usually named with x is processed through fixed equations and produces an outcome, an result

a)4
b)17
c)0

3.f(x)=x/4-5

1 Like

[quote=ā€œbiggabiggs, post:5324, topic:8429ā€]
Hi Maki. I learned BASIC programming a long time ago and was taught to think logically when programming but there seems to be many explanation left out in breaking down for a beginner in Javascript, I have learned in this course how to call a function whilst at the same time passing a value to its parameter to be used within that function block. We are given several easy to understanding examples and then we are given the code of a function calling another function with no proper breakdown of how it works. If var triple = multiple(3) then triple = the value in multiple(3).
Also when var triple is created as equal to multiple(3), does it automatically become triple(3).
Also function fn(y) is a named function within the multiple(3) function, so why isn’t fn(y) called?
You’ve explained that triple(y) is fn(y) so why create triple(y) instead of just calling fn(y)
I know the program must work, so what am I missing here? Is fn a reserved word for function that is automatically given a call variable such as triple(y).
please can you break it down a little bit more based on my confusion?

I can’t progress any further until I understand how this works. I’ve seen examples of functions calling other functions in a simple call stack example and understood them but not so much when they give a more complex but shorter version for the same result for more advanced students. Could it be that the example i’ve been given isn’t for a beginner to understand and I shouldn’t try to figure it out because of my limited java knowledge and just move on?

// Example: Function Returning a Function
// function multiple(x) {

function fn(y)
{
    return x * y;
}

return fn;

}

var triple = multiple(3);
triple(2); // returns 6
triple(3); // returns 9

/* I learned BASIC programming a long time ago and was taught to think logically when programming but there seems to be much explanation left out in breaking down for a beginner in Javascript, I have learned in this course how to call a function whilst at the same time passing a value to its parameter to be used within that function block. We are given several easy-to-understand examples and then we are given the code of a function calling another function with no proper breakdown of how it works. If var triple = multiple(3) then triple = the value in multiple(3).
Also when var triple is created as equal to multiple(3), does it automatically become triple(3).
Also function fn(y) is a named function within the multiple(3) function, so why isn’t fn(y) called?
You’ve explained that triple(y) is fn(y) so why create triple(y) instead of just calling fn(y)
I know the program must work, so what am I missing here? Is fn a reserved word for a function that is automatically given a call variable such as triple(y)
please can you break it down a little bit more based on my confusion?

I can’t progress any further until I understand how this works. I’ve seen examples of functions calling other functions in a simple call stack example and understood them but not so much when they give a more complex but shorter version for the same result for more advanced students. Could it be that the example I’ve been given isn’t for a beginner to understand and I shouldn’t try to figure it out because of my limited java knowledge and just move on?

Can someone simplify what each line of code does, so that I can make sense of it? Thank you.
*/

a) f(2) = 4
b) f(7) = 17
c) f(0) = 0

1 Like
  1. A function does the same actions to each unique variable entered.
  2. a) 4
    b) 17
    c)0
  3. f(x) = (x/4)-5
1 Like

you cannot call the function inside the mutiple function direct, you only get access to that function through the main function(multiple) , so you have to store in a variable the return value form the multiple function, since the return value is a function after u get it from the main function then you call that function to get what the function returns. I know it is complicated to understand but if you want to get deeper to code you can take Javascript course. And plz there is no need to stack here if you understand the basics about functions you are good to continue the next lessons.

1 Like

what happened to answer 3šŸ¤”

  1. A function takes an input, applies some form of computation, and produces an output

  2. a. 4 b. 17 c. 0

  3. f(x) = { (x / 4) - 5 }

1 Like

Thanks Maki, I think I thought I understood the basics of functions until this came along. Can you not break down each line for me. That’s what I need someone to do to clarify it for me.

The only bit that you haven’t explained to me is why the triple(2) becomes fn(y).
Is fn a reserved word different from other variables? That is the bit that doesn’t make sense to me because I can find nowhere that explains it. I’ve been trying to ask you to explain that snippet of code for me but maybe I’m not explaining myself properly.

1.A function describes the calculation to be performed on any given input.
2. a. 4
2.b. 17
2.c. 0
3. f(x)=x/4-5

1 Like

A function is a block of code that can be called upon whenever it is needed, as many times as it is needed.

  1. A function is like a machine that has an input and output and the output is related to the input

  2. Output functions

  • 4

  • 17

  • 0

  1. f(x)=(x/4)-5
1 Like
  1. A mathematical function is a rule that gives value of a dependent variable that corresponds to specified values of one or more independent variables.ž

  2. 4, 17, 0

  3. f(x) = x / 4 - 5

2 Likes
  1. A function is a code that requires an input that generates an output.

  2. f(x) = {x^2 = 0}
    f(x) = {x+10 = 1}
    a) 4
    b) 17
    c) 0

  3. f(x) = (x/4)-5

1 Like
  1. Computation of input giving an output as result
  2. a)4 b)17 c)0
  3. f(x) = (x/4) -5
1 Like
  1. A function performs a computation on an input, thereby producing an output.

  2. f(2) = 4
    f(7) = 17
    f(0) = 0

  3. f(x) = x/4 - 5

2 Likes

A function effects an input variable and the product of a function depends on the value of the input variable.

a) 4
b) 17
c) 0

f(x) = (x/4) - 5

1 Like
  1. A function is a computation that takes an input, computes, and gives the output.
  2. a. 4, b. 17, c. 0
  3. f(x) = (x/4) - 5
1 Like