Skip to content

Commit bb31a50

Browse files
committed
completed closure.js MVP task
1 parent cbc83ea commit bb31a50

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

assignments/closure.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
// that manipulates variables defined in the outer scope.
55
// The outer scope can be a parent function, or the top level of the script.
66

7+
let numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
8+
function calculator(arr) {
9+
let random = arr[Math.floor(Math.random() * arr.length)];
10+
11+
return function squareNums() {
12+
let square = random * random;
13+
console.log(`The square of ${random} is ${square}`)
14+
return square;
15+
};
16+
}
717

8-
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
18+
calculator(numbers)();
919

20+
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
1021

1122
// ==== Challenge 2: Implement a "counter maker" function ====
1223
const counterMaker = () => {

0 commit comments

Comments
 (0)