-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14-Day.js
More file actions
22 lines (18 loc) · 691 Bytes
/
14-Day.js
File metadata and controls
22 lines (18 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function createCounter() {
let count = 0; // initialize count to 0
// define and return a function that increments count and returns its value
return function () {
count++; // increment count by 1
return count; // return the new value of count
};
}
// create a new counter function
const counter = createCounter();
// call the counter function multiple times and log the result
console.log(counter()); // prints 1
console.log(counter()); // prints 2
console.log(counter()); // prints 3
console.log(counter()); // prints 4
console.log(counter()); // prints 5
console.log(counter()); // prints 6
console.log(counter()); // prints 7