Return Lecture part 6 what am I doing wrong?

Please help me find my mistake, in that I having problems with step 4.

Step 1: Imagine if we needed to order monitors for everyone in an office and this office is conveniently arranged in a grid shape. We could use a function to help us calculate the number of monitors needed!

Declare a function monitorCount() that has two parameters. The first parameter is rows and the second parameter is columns .

Step 2: Let’s compute the number of monitors by multiplying rows and columns and then returning the value.

In the function body of the function you just wrote, use the return keyword to return rows * columns .

Step 3: Now that the function is defined, we can compute the number of monitors needed. Let’s say that the office has 5 rows and 4 columns.

Declare a variable named numOfMonitors using the const keyword and assign numOfMonitors the value of invoking monitorCount() with the arguments 5 and 4 .

Step 4: To check that the function worked properly, log numOfMonitors to the console.

Here’s my Code!

function monitorCount(rows,columns){

const numOfMonitors = monitorCount(5,4);

return rows * columns;

console.log(numOfMonitors);

}

Hello @crazy-chrome, welcome to the forums! You problem is that this

and this

Should be outside the function. Step two is asking you to return rows * columns. You don’t need to store this to a variable, but just return it:

return rows * columns;

But that is just to do with CC’s lesson. This will never run:

That is because it is inside the function, but after the return when you have a return in a function, it effectively ends that function, which means that no code after the return will run:

function foo(){
  console.log("foo");
  return "bar";
  console.log("This won't print");
}

foo();
console.log(foo());
console.log("Outside the function");

This prints:

>>foo //because you are calling the function, it will execute the console.log()
>>foo//because you have called it again (inside the console.log) it will print 'foo' again
>>bar//because you are printing the return of the function ('bar')
>>Outside the function//because this is now outside of the function, and will carry on as normal.
//Notice how 'this won't print' isn't printed? That is because it is inside the 
//function, but after the return.

I hope this helps!