Skip to content

Conversation

@Jess2896
Copy link
Owner

@Jess2896 Jess2896 commented Sep 26, 2019

  • 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.

@Jess2896 Jess2896 changed the title Calculates which team has the highest average score Second challenge Sep 26, 2019
Copy link
Collaborator

@oscarpolanco oscarpolanco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can update the conditions, but first I would like to read if you have another approach to change these conditions.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option i can think of is to save the possible results in variables so the code is easier to read.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space here

script.js Outdated
let maryAvrg = calcAverage(maryTeamScores);
let winner = "The three teams are tied";

if (maryAvrg > johnsAvrg && maryAvrg> mikesAvrg) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space here

script.js Outdated
scores.forEach(score => {
sum += score;
});
return sum/scores.length;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space here

script.js Outdated
@@ -0,0 +1,35 @@
let johnTeamScores = [89,20,103];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should re-check this definition.
Can you give me some inside about let, const and var?

Copy link
Owner Author

@Jess2896 Jess2896 Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces here

script.js Outdated
@@ -0,0 +1,35 @@
let johnTeamScores = [89,20,103];
let mikeTeamScores = [116,94,123];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces here

script.js Outdated

//Extra

let maryTeamScores = [97,134,105];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces here

@Jess2896 Jess2896 force-pushed the second-challenge branch 4 times, most recently from 86428b0 to 81dd312 Compare October 7, 2019 14:51
@Jess2896 Jess2896 force-pushed the second-challenge branch 5 times, most recently from 33dedfe to d6134d7 Compare October 14, 2019 15:04
script.js Outdated
higherAverage.highestAvrg = '';
}

const avrg = higherAverage.winner + higherAverage.highestAvrg + higherAverage.score;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?


higherAverage.setWinner();

function calcAverage(scores) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello can we add some documentation for the code here and here are some examples

@Jess2896 Jess2896 force-pushed the second-challenge branch 5 times, most recently from c08f800 to 1603edf Compare October 15, 2019 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants