-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleExtraPixelsToPercentage.html
47 lines (36 loc) · 1.22 KB
/
ConsoleExtraPixelsToPercentage.html
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
<label for="tb">Console<br/><textarea id="tb" style="height:500px;width:500px;"></textarea></label>
<script>
function printNl(text){
var tb = document.getElementById("tb");
if(tb){
if(typeof(text) === 'object'){
text = JSON.stringify(text);
}
var currentVal = tb.value;
if(currentVal === ''){
currentVal += text.toString();
}else{
currentVal += '\r\n' + text.toString();
}
tb.value = currentVal;
}
}
var vidder = [{pixels:28},{pixels:55},{pixels:30},{pixels:280},{pixels:400},{pixels:150},{pixels:40},{pixels:28}];
var sum = 0;
var prosentSum = 0;
vidder.forEach(function(vidde){
sum += vidde.pixels;
});
vidder.forEach(function(vidde){
vidde.prosent = parseFloat(((vidde.pixels/sum)*100).toFixed(1));
});
//printNl(vidder);
vidder.forEach(function(vidde){
prosentSum += vidde.prosent;
});
vidder.forEach(function(vidde){
printNl(vidde.pixels + "px : " + vidde.prosent + "%");
});
printNl("Pixel total: " + sum);
printNl("Prosent total: " + prosentSum);
</script>