I’m examing this code and am trying to figure out why the parameters of monitorCount
need to be reiterated in the costOfMonitors
function? The return of monitorCount
is rows * columns
.
Wouldn’t you then be able to simply make the return of costOfMonitors
:
return monitorCount * 200;
because monitorCount
has already been returned/determined with:
function monitorCount(rows, columns) {
return rows * columns;
Here’s all the code:
function monitorCount(rows, columns) {
return rows * columns;
}
function costOfMonitors(rows, columns)
{
return monitorCount(rows, columns) * 200;
}
const totalCost = costOfMonitors(5, 4);
console.log(totalCost);
Hello @El_Escandalo
monitorCount function has two parameters so to take it’s return value you have to call monitorCount function with arguments otherwise it won’t be return value(rows*columns) , it will return NaN.
You can use costOfMonitors function only but here is two different functions so in my opinion it’s better to divide this code in two functions because it will give a better understanding.
1 Like
Thanks but aren’t the arguments called already in the 2nd line of code? Does a return
not “hold” the values?
function monitorCount(rows, columns) {
return rows * columns;
}
You can use costOfMonitors function only but here is two different functions so in my opinion it’s better to divide this code in two functions because it will give a better understanding.
1 Like
To make use of that return value, you’ll need to give it some data to work with. That’s how the monitorCount
function is defined.
Just because they happen to have the same parameter names doesn’t mean they “share” them and you can omit them when calling monitorCount
.
1 Like
@dev-313 is correct. If you return monitorCount without parameters it is going to run that function without the parameters it needs, so think of it as calling monitorCount()
with nothing being passed into it.
2 Likes
@kevcomedia Thanks- but if they don’t “share” the parameters, then at what point is monitor count assigned an argument? Am I right in thinking that const totalCost = costOfMonitors(5, 4);
assigns totalCost
the function of costOfMonitors
with the arguments of 5, 4, but where is monitorCount assigned an argument, if the variables rows, columns
are not shared?
The rows
and columns
values from costOfMonitors
are explicitly passed to monitorCount
right at the return statement of costOfMonitors
.
1 Like