-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClosures(add, mult, subtract).html
More file actions
48 lines (40 loc) · 986 Bytes
/
Copy pathClosures(add, mult, subtract).html
File metadata and controls
48 lines (40 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!doctype html>
<html lang="en">
<head>
<title>Closures</title>
<meta charset="utf-8">
<script>
//OPEN CONSOLE TO SEE RESULTS
function makeAddition(n) {
return function(x) {
return x+n;
}
}
//supply 4 as argument for the value of 'n'
var add = makeAddition(4);
//supply 2 as argument for the value of 'x'
console.log("result after addition: " + add(2));
console.log("--------------");
function makeMultiplication(n) {
return function(x) {
return x*n;
}
}
//supply 4 as argument for the value of 'n'
var multiply = makeMultiplication(4);
//supply 2 as argument for the value of 'x'
console.log("result after multiplication: " + multiply(2));
console.log("--------------");
function makeSubtraction(n) {
return function(x) {
return x-n;
}
}
//supply 4 as argument for the value of 'n'
var subtract = makeSubtraction(4);
//supply 2 as argument for the value of 'x'
console.log("result after subtraction: " + subtract(2));
</script>
</head>
<body> </body>
</html>