Help me solve this function problem

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

I am trying to learn about closures in Javascript, and I have been working on this problem, and I just can’t wrap my head around how it is supposed to work. Can anyone give me a possible solution and explain why it works like that?



/*
  Write a function called makeCounter that makes the following code work properly.
*/  


//Uncomment this once you make your function
//   var count = makeCounter();
//   count(); // 1
//   count(); // 2
//   count(); // 3
//   count(); // 4

What are the instructions?

The instructions are listed.

“Write a function called makeCounter that makes the following code work properly”

I figured it out.

Here’s how I did it:

function makeCounter() {
var num = 1;
return function () {
console.log(num++);
}
}

var count = makeCounter();
count(); // 1
count(); // 2
count(); // 3
count(); // 4

Btw you shoudlt post anwsers in this fourms… so i would delete your post if i were you.

The problem I listed was a problem from a 3rd party site (not this one).