1
+ /*
2
+ ==================================================================================
3
+ NOTE:
4
+
5
+ The use of global variables is not recommended, due to higher risk of errors.
6
+
7
+ The code below serves only demonstration purposes.
8
+ ==================================================================================
9
+ */
10
+
11
+ //Will contain Instances of HealthyGenes or Cancer
12
+ var healthyGenes = [ ] ;
13
+ var unhealthyGenes = [ ] ;
14
+
15
+
16
+ //=======================
17
+ //Class HealthyGenes
18
+ //=======================
19
+ function HealthyGenes ( ) { } ;
20
+
21
+ //Generates prototype methods of HealthyGenes
22
+ for ( var method = 0 ; method < 100 ; method ++ )
23
+ {
24
+
25
+ HealthyGenes . prototype [ "GROWTH" + method ] = function ( )
26
+ {
27
+ var growth_InPercent = method
28
+
29
+ return growth_InPercent ;
30
+ } ;
31
+ }
32
+
33
+
34
+ //=======================
35
+ //Class Cancer
36
+ //=======================
37
+ function Cancer ( )
38
+ {
39
+ //Generates methods within Cancer
40
+ for ( var method = 0 ; method < 100 ; method ++ )
41
+ {
42
+
43
+ this [ method ] = function ( )
44
+ {
45
+ var growth_InPercent = method
46
+
47
+ return growth_InPercent ;
48
+ } ;
49
+ }
50
+ } ;
51
+
52
+
53
+ //=======================
54
+ //Inputs
55
+ //=======================
56
+
57
+ //Generates dynamic numbers of Cancer or HealthyGenes instances
58
+ function numOfGrowth ( )
59
+ {
60
+ //Converting to type number with the "+" operator
61
+ var genes = + document . getElementById ( 'num-of-growth' ) . value ;
62
+ var healthy = document . getElementById ( 'healthy-growth' ) ;
63
+ var unhealthy = document . getElementById ( 'unhealthy-growth' ) ;
64
+
65
+
66
+
67
+ //Resete genes if number of growth(user input) is reduced
68
+ if ( healthy . checked && ( genes < healthyGenes . length ) )
69
+ {
70
+ healthyGenes = [ ] ;
71
+
72
+ }
73
+ else if ( unhealthy . checked && ( genes < unhealthyGenes . length ) )
74
+ {
75
+ unhealthyGenes = [ ] ;
76
+
77
+ }
78
+
79
+
80
+ //Generating HealthyGenes instances
81
+ for ( var gene = 0 ; gene < genes ; gene ++ )
82
+ {
83
+
84
+
85
+ if ( healthy . checked )
86
+ {
87
+
88
+ healthyGenes [ gene ] = new HealthyGenes ( ) ;
89
+
90
+ }
91
+ else if ( unhealthy . checked )
92
+ {
93
+
94
+ unhealthyGenes [ gene ] = new Cancer ( ) ;
95
+
96
+ }
97
+ else
98
+ {
99
+ alert ( "ERROR: Type of Growth doesn`t exist! Please check code..." ) ;
100
+ }
101
+
102
+ }
103
+
104
+ }
105
+
106
+
107
+ //Reloades page (releasing memory)
108
+ function refresh ( )
109
+ {
110
+ location . reload ( ) ;
111
+ }
112
+
113
+
114
+ //Change picture depending on the selected radio buttons
115
+ var loadImage = function ( )
116
+ {
117
+ var healthy = document . getElementById ( 'healthy-growth' ) ;
118
+ var unhealthy = document . getElementById ( 'unhealthy-growth' ) ;
119
+ var image = document . getElementById ( 'genetic-pic' ) ;
120
+
121
+
122
+ if ( unhealthy . checked )
123
+ {
124
+ image . src = "Cancer.jpg" ;
125
+ }
126
+ else if ( healthy . checked )
127
+ {
128
+ image . src = "Healthy.jpg" ;
129
+ }
130
+ else
131
+ {
132
+ alert ( "WARNING: Missing image!" ) ;
133
+ }
134
+
135
+ } ;
136
+
137
+ //Initializing image when page is loaded the first time
138
+ loadImage ( ) ;
0 commit comments