|
1 | | -let johnTeamScores = [89,20,103]; |
2 | | -let mikeTeamScores = [116,94,123]; |
| 1 | +const johnTeamScores = [89,20,103]; |
| 2 | +const mikeTeamScores = [116,94,123]; |
| 3 | + |
3 | 4 | let johnsAvrg = calcAverage(johnTeamScores); |
4 | 5 | let mikesAvrg = calcAverage(mikeTeamScores); |
5 | | -let hasHigherScore = johnsAvrg > mikesAvrg? "John's team has a higher average of " + johnsAvrg : "Mike's team has a higher average of " + mikesAvrg; |
6 | | -let avrg = johnsAvrg == mikesAvrg? "John's and Mike's teams have the same average score" : hasHigherScore; |
| 6 | + |
| 7 | +let hasHigherScore = johnsAvrg > mikesAvrg ? "John's team has a higher average of " + johnsAvrg : "Mike's team has a higher average of " + mikesAvrg; |
| 8 | +let avrg = johnsAvrg == mikesAvrg ? "John's and Mike's teams have the same average score" : hasHigherScore; |
7 | 9 |
|
8 | 10 | function calcAverage(scores) { |
| 11 | + |
9 | 12 | let sum = 0; |
| 13 | + |
10 | 14 | scores.forEach(score => { |
11 | 15 | sum += score; |
12 | 16 | }); |
13 | | - return sum/scores.length; |
| 17 | + |
| 18 | + return sum / scores.length; |
14 | 19 | } |
15 | 20 |
|
16 | 21 | //Extra |
17 | 22 |
|
18 | | -let maryTeamScores = [97,134,105]; |
| 23 | +const maryTeamScores = [97,134,105]; |
| 24 | + |
19 | 25 | let maryAvrg = calcAverage(maryTeamScores); |
20 | 26 | let winner = "The three teams are tied"; |
21 | 27 |
|
22 | | -if (maryAvrg > johnsAvrg && maryAvrg> mikesAvrg) { |
| 28 | +if (maryAvrg > johnsAvrg && maryAvrg > mikesAvrg) { |
23 | 29 | winner = "Mary's team has the highest average score of " + maryAvrg; |
24 | 30 | } |
25 | 31 | else if (maryAvrg !== johnsAvrg && maryAvrg !== mikesAvrg) { |
|
0 commit comments