-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.js
110 lines (76 loc) · 1.64 KB
/
block.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
/*
NOTE:
the varibale "elMedia" serves here only for demonstartion purposes.
Global vaiables should be avoided!
*/
//A list with all checked media
var elMedia = [];
//Lists all checked electro Media
function checkElectroMedia()
{
var media = document.getElementsByClassName('Emedia');
for(var i = 0; i < media.length; i++ )
{
if(media[i].checked)
{
elMedia.push(media[i]);
}
}
}
//Version false: checkMedia, checkElectroMedia
//Version true: checkMedia, checkMedia
function Version(broken)
{
var checkMedia = checkElectroMedia;
var result = document.getElementById('result');
result.innerHTML = " "; //Reset content
elMedia.length = 0; //Reset array by putting its length to zero
//Set to true to check block scoping
if(true)
{
var media = document.getElementsByClassName('Nmedia');
var noelMedia = [];
/*
ATTENTION:
Overwrites the variable "media" as a new function
and stays overwritten after leaving the if-block!
*/
checkMedia = function()
{
for(var i = 0; i < media.length; i++ )
{
if(media[i].checked)
{
noelMedia.push(media[i]);
}
}
}
checkMedia();
//Showing the result in browser
for(var j = 0; j < noelMedia.length; j++)
{
result.innerHTML += " " + noelMedia[j].value;
}
}
if(broken)
{
/*
ATTENTION:
Function does not work as "checkElectroMedia"
*/
checkMedia();
}
else
{
/*
ATTENTION:
Works fine as expected
*/
checkElectroMedia();
}
//Showing the result in browser
for(var j = 0; j < elMedia.length; j++)
{
result.innerHTML += " " + elMedia[j].value;
}
}