Skip to content

Commit 3788b52

Browse files
committed
created two files
1 parent 750eb80 commit 3788b52

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

bubbletest.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Bubble Test</title>
5+
<script type="text/javascript">
6+
var scores = [60, 50, 60, 58, 54, 54,
7+
58, 50, 52, 54, 48, 69,
8+
34, 55, 51, 52, 44, 51,
9+
69, 64, 66, 55, 52, 61,
10+
46, 31, 57, 52, 44, 18,
11+
41, 53, 55, 61, 51, 44];
12+
13+
var costs = [.25, .27, .25, .25, .25, .25,
14+
.33, .31, .25, .29, .27, .22,
15+
.31, .25, .25, .33, .21, .25,
16+
.25, .25, .28, .25, .24, .22,
17+
.20, .25, .30, .25, .24, .25,
18+
.25, .25, .27, .25, .26, .29];
19+
20+
function getAndPrintHighestScore (scoresX) {
21+
//var scores.length = scores.length;
22+
var highScoreX = 0;
23+
24+
for (var i = 0; i < scoresX.length; i++) {
25+
document.write("Bubble soluntion " + i + "# " + "scores: " + scoresX[i] + "<br>");
26+
if (scoresX[i] > highScoreX) {
27+
highScoreX = scoresX[i];
28+
}
29+
}
30+
31+
return highScoreX;
32+
}
33+
34+
var highScore = getAndPrintHighestScore(scores);
35+
document.write("Bubble Tests: " + scores.length + "<br>");
36+
document.write("Highest Bubble score: " + highScore + "<br>");
37+
38+
function getBestResults (score1, highScore1) {
39+
var scoreIndex = [];
40+
for (var i = 0; i < score1.length; i++) {
41+
if (score1[i] == highScore1) {
42+
scoreIndex.push(i);
43+
}
44+
}
45+
return scoreIndex;
46+
}
47+
48+
var scoreIndex1 = getBestResults(scores, highScore);
49+
document.write("solution with highest Bubble score is: " + scoreIndex1 + "<br>");
50+
51+
function getMostCostEffectiveSolution (scoresZ, costsZ, highScoreZ) {
52+
var cost = 100;
53+
var index = 0;
54+
55+
for (var i = 0; i < scoresZ.length; i++) {
56+
if(scoresZ[i] == highScoreZ){
57+
if (cost > costsZ[i]) {
58+
index = i;
59+
cost = costsZ[i];
60+
}
61+
}
62+
}
63+
64+
return index;
65+
}
66+
67+
var mostCostEffective = getMostCostEffectiveSolution(scores, costs, highScore);
68+
69+
document.write("Bubble Solution #" + mostCostEffective + " is the most cost effective");
70+
</script>
71+
</head>
72+
<body>
73+
74+
</body>
75+
</html>

chapter4/bubbles.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
bestSolutions.push(i);
4848
}
4949
}
50-
console.log("Solutions with the highest score: " + bestSolutions);
50+
document.write("Solutions with the highest score: " + bestSolutions);
5151
</script>
5252
</head>
5353
<body>

0 commit comments

Comments
 (0)