forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbletest.html
More file actions
75 lines (62 loc) · 1.88 KB
/
bubbletest.html
File metadata and controls
75 lines (62 loc) · 1.88 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Bubble Test</title>
<script type="text/javascript">
var scores = [60, 50, 60, 58, 54, 54,
58, 50, 52, 54, 48, 69,
34, 55, 51, 52, 44, 51,
69, 64, 66, 55, 52, 61,
46, 31, 57, 52, 44, 18,
41, 53, 55, 61, 51, 44];
var costs = [.25, .27, .25, .25, .25, .25,
.33, .31, .25, .29, .27, .22,
.31, .25, .25, .33, .21, .25,
.25, .25, .28, .25, .24, .22,
.20, .25, .30, .25, .24, .25,
.25, .25, .27, .25, .26, .29];
function getAndPrintHighestScore (scoresX) {
//var scores.length = scores.length;
var highScoreX = 0;
for (var i = 0; i < scoresX.length; i++) {
document.write("Bubble soluntion " + i + "# " + "scores: " + scoresX[i] + "<br>");
if (scoresX[i] > highScoreX) {
highScoreX = scoresX[i];
}
}
return highScoreX;
}
var highScore = getAndPrintHighestScore(scores);
document.write("Bubble Tests: " + scores.length + "<br>");
document.write("Highest Bubble score: " + highScore + "<br>");
function getBestResults (score1, highScore1) {
var scoreIndex = [];
for (var i = 0; i < score1.length; i++) {
if (score1[i] == highScore1) {
scoreIndex.push(i);
}
}
return scoreIndex;
}
var scoreIndex1 = getBestResults(scores, highScore);
document.write("solution with highest Bubble score is: " + scoreIndex1 + "<br>");
function getMostCostEffectiveSolution (scoresZ, costsZ, highScoreZ) {
var cost = 100;
var index = 0;
for (var i = 0; i < scoresZ.length; i++) {
if(scoresZ[i] == highScoreZ){
if (cost > costsZ[i]) {
index = i;
cost = costsZ[i];
}
}
}
return index;
}
var mostCostEffective = getMostCostEffectiveSolution(scores, costs, highScore);
document.write("Bubble Solution #" + mostCostEffective + " is the most cost effective");
</script>
</head>
<body>
</body>
</html>