-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosures.js
87 lines (67 loc) · 1.58 KB
/
closures.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Contains all the needed features of the sphere
function Sphere()
{
//Similar to member variables
var title = undefined;
var material = undefined;
var radius = undefined;
//similar to methods
return {
setTitle: function(newTitle)//SET
{
title = newTitle;
},
setMaterial: function(newMaterial)
{
material = newMaterial;
},
setRadius: function(newRadius)
{
radius = newRadius;
},
getTitle:function()//GET
{
return title;
},
getMaterial:function()
{
return material;
},
getRadius:function()
{
return radius;
}
};
}
/*
NOTE:
There are many ways to realize the systems code.
The focus here lies on closures and it is recommended to see the code as a minimum solution.
*/
function Title()
{
var mySphere = Sphere();
var resOne = document.getElementById('resOne');
//setting the value from browser input
mySphere.setTitle( document.getElementById('title').value );
//Shows result in browser
resOne.innerHTML = mySphere.getTitle();
}
function Material()
{
var mySphere = Sphere();
var resTwo = document.getElementById('resTwo');
//setting the value from browser input
mySphere.setMaterial( document.getElementById('material').value );
//Shows result in browser
resTwo.innerHTML = mySphere.getMaterial();
}
function Radius()
{
var mySphere = Sphere();
var resTwo = document.getElementById('resThree');
//setting the value from browser input
mySphere.setRadius( document.getElementById('radius').value );
//Shows result in browser
resThree.innerHTML = mySphere.getRadius() + " miles";
}