en.javascript.info/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md
Ilya Kantor b6adf0b6aa up
2019-07-31 23:18:20 +03:00

483 B

importance: 5


Set and decrease for counter

Modify the code of makeCounter() so that the counter can also decrease and set the number:

  • counter() should return the next number (as before).
  • counter.set(value) should set the counter to value.
  • counter.decrease() should decrease the counter by 1.

See the sandbox code for the complete usage example.

P.S. You can use either a closure or the function property to keep the current count. Or write both variants.