I am new to JavaScript. I have this piece of code. I need to print the following:
//counter() should return the next number.
//counter.set(value) should set the counter to value.
//counter.decrease() should decrease the counter by 1
function makeCounter() {
let count = 0;
function counter() {
return count++;
}
counter.decrease = function () {
return count--;
};
counter.set = function (value) {
return count = value;
};
}
How can I call the 3 nested functions outside?
counteroutside if it's not exposed. Are you supposed to change this code? Or what should be done here?makeCounteror you canreturn counterfrom inside. Yet it might be neither. Hence my questions to you - are you supposed to change the code? Or what should be done here?