-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.js
138 lines (100 loc) · 2.54 KB
/
methods.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
==================================================================================
NOTE:
The use of global variables is not recommended, due to higher risk of errors.
The code below serves only demonstration purposes.
==================================================================================
*/
//Will contain Instances of HealthyGenes or Cancer
var healthyGenes = [];
var unhealthyGenes = [];
//=======================
//Class HealthyGenes
//=======================
function HealthyGenes(){};
//Generates prototype methods of HealthyGenes
for(var method = 0; method < 100; method++)
{
HealthyGenes.prototype["GROWTH" + method] = function()
{
var growth_InPercent = method
return growth_InPercent;
};
}
//=======================
//Class Cancer
//=======================
function Cancer()
{
//Generates methods within Cancer
for(var method = 0; method < 100; method++)
{
this[method] = function()
{
var growth_InPercent = method
return growth_InPercent;
};
}
};
//=======================
//Inputs
//=======================
//Generates dynamic numbers of Cancer or HealthyGenes instances
function numOfGrowth()
{
//Converting to type number with the "+" operator
var genes = +document.getElementById('num-of-growth').value;
var healthy = document.getElementById('healthy-growth');
var unhealthy = document.getElementById('unhealthy-growth');
//Resete genes if number of growth(user input) is reduced
if(healthy.checked && (genes < healthyGenes.length))
{
healthyGenes = [];
}
else if(unhealthy.checked && (genes < unhealthyGenes.length))
{
unhealthyGenes = [];
}
//Generating HealthyGenes instances
for(var gene = 0; gene < genes; gene++)
{
if(healthy.checked)
{
healthyGenes[gene] = new HealthyGenes();
}
else if(unhealthy.checked)
{
unhealthyGenes[gene] = new Cancer();
}
else
{
alert("ERROR: Type of Growth doesn`t exist! Please check code...");
}
}
}
//Reloades page (releasing memory)
function refresh()
{
location.reload();
}
//Change picture depending on the selected radio buttons
var loadImage = function()
{
var healthy = document.getElementById('healthy-growth');
var unhealthy = document.getElementById('unhealthy-growth');
var image = document.getElementById('genetic-pic');
if(unhealthy.checked)
{
image.src = "Cancer.jpg";
}
else if(healthy.checked)
{
image.src = "Healthy.jpg";
}
else
{
alert("WARNING: Missing image!");
}
};
//Initializing image when page is loaded the first time
loadImage();