What is the point of this function?

Hi,
So I alright executing the exercise, but I would like to know WHY the function needs the ‘Russian doll’ like encasing, what is the purpose?
e.g:

function monitorCount(rows, columns) {
  return rows * columns;
};
const numOfMonitors=monitorCount(5,4);
console.log(numOfMonitors);

So I determine the function on the first line! I am fine with that… then I carry on and set the way the function will be calculated. Great! What is the const line for then? is that were basically the DATA will be input to, so the function can work? I am a bit lost on this concept.

I didn’t see the point of the function to begin with, I could have made a const without calling the function, what is this for?

Thx

Despite the verbosity, the function demonstrates how we can keep all multiplication of two factors contained in one function, which any part of the program can call upon if it needs a product of a and b.

For this exercise it is more specific so we can see what is happening, but it wouldn’t have to be like that.

 const multiply = (a, b) => a * b;    // generic function expression

Then we could use named variables in the program…

rows = 5
columns = 4
let numOfMonitors = multiply(rows, columns)
console.log(numOfMonitors)

The function name says what it does, and we can see that if we want to know how many monitors there are, multiply rows times columns.

1 Like

Sure, you could just do this: console.log(5 * 4), but what would that teach you about how functions work, or what the return statement does? The lessons use simple examples to teach concepts and techniques that can be used to accomplish very complex tasks.

2 Likes