Conversation
25e0b22 to
3c1e335
Compare
3c1e335 to
ef740e4
Compare
5cb1605 to
9ab399e
Compare
oscarpolanco
left a comment
There was a problem hiding this comment.
Good job!!
Some comments that we can discuss
script.js
Outdated
| let mikeTeamScores = [116,94,123]; | ||
| let johnsAvrg = calcAverage(johnTeamScores); | ||
| let mikesAvrg = calcAverage(mikeTeamScores); | ||
| let hasHigherScore = johnsAvrg > mikesAvrg? "John's team has a higher average of " + johnsAvrg : "Mike's team has a higher average of " + mikesAvrg; |
There was a problem hiding this comment.
I think we can update the conditions, but first I would like to read if you have another approach to change these conditions.
There was a problem hiding this comment.
The other option i can think of is to save the possible results in variables so the code is easier to read.
There was a problem hiding this comment.
Can we store the winner on some kind of structure like an object so we don't need to repeat the string so many times?
There was a problem hiding this comment.
Changed it, is it fine like this?
script.js
Outdated
| let johnsAvrg = calcAverage(johnTeamScores); | ||
| let mikesAvrg = calcAverage(mikeTeamScores); | ||
| let hasHigherScore = johnsAvrg > mikesAvrg? "John's team has a higher average of " + johnsAvrg : "Mike's team has a higher average of " + mikesAvrg; | ||
| let avrg = johnsAvrg == mikesAvrg? "John's and Mike's teams have the same average score" : hasHigherScore; |
script.js
Outdated
| let maryAvrg = calcAverage(maryTeamScores); | ||
| let winner = "The three teams are tied"; | ||
|
|
||
| if (maryAvrg > johnsAvrg && maryAvrg> mikesAvrg) { |
script.js
Outdated
| scores.forEach(score => { | ||
| sum += score; | ||
| }); | ||
| return sum/scores.length; |
script.js
Outdated
| @@ -0,0 +1,35 @@ | |||
| let johnTeamScores = [89,20,103]; | |||
There was a problem hiding this comment.
I think you should re-check this definition.
Can you give me some inside about let, const and var?
There was a problem hiding this comment.
The main difference between var and let is that let is block-scoped instead of function-scoped, which is considered a better coding practice. Let also doesn't allow you to access a variable before its declared.
On the other hand, const is similar to let, the difference being that you can't assign a new value to the variable.
I realized I should have declared the scores as const since I don't need to change these values. Fixed the code.
script.js
Outdated
| @@ -0,0 +1,35 @@ | |||
| let johnTeamScores = [89,20,103]; | |||
script.js
Outdated
| @@ -0,0 +1,35 @@ | |||
| let johnTeamScores = [89,20,103]; | |||
| let mikeTeamScores = [116,94,123]; | |||
script.js
Outdated
|
|
||
| //Extra | ||
|
|
||
| let maryTeamScores = [97,134,105]; |
86428b0 to
81dd312
Compare
33dedfe to
d6134d7
Compare
script.js
Outdated
| higherAverage.highestAvrg = ''; | ||
| } | ||
|
|
||
| const avrg = higherAverage.winner + higherAverage.highestAvrg + higherAverage.score; |
There was a problem hiding this comment.
On Es6 were introduce the template literals. We can use it here instead of storing the complete string value; just need to put it twice in case there was a tie.
|
|
||
| higherAverage.setWinner(); | ||
|
|
||
| function calcAverage(scores) { |
c08f800 to
1603edf
Compare
1603edf to
f3be13a
Compare
Calculates which team has the highest average score and prints the result in the console.
The extra part of this challenge consisted on adding a third team and determining which of the 3 has the highest average score.
Verification steps
Download both files(index.html and script.js) into a folder and then open the index.html file on a browser.
Inspect the website and open the console to see the result obtained.