Easy there, pal!
To access the Objects challenges in the JavaScript programming, you need to sign up and subscribe first.
Muffin respects football, but sometimes he is too lazy busy to watch games. But he doesn’t worry, because it’s enough for a cat to know the names of the best scorers and their effectiveness in order to bet on a player to keep the conversation going at the right time.
While you were writing the game, a letter from Muffin arrived. It was marked “I needed it done yesterday”.
Meow! I need a program that will calculate the usefulness and effectiveness of players based on their statistics. Design the code as a
getStatisticsfunction with one parameter: an array of players.Each football player in this array is described by an object with three fields: name (property
name), goals scored (propertygoals) and goal passes (propertypasses).The function must return the same array, in which each player has two more fields added: effectiveness coefficient as per Muffin® (property
coefficient) and performance (propertypercent).
- The effectiveness coefficient is calculated like this: multiply the player’s goals by
2(because I think that goals are the most important thing) and add all passes by the football player that resulted in a goal to this value.- The effectiveness (percentage of goals scored by a football player against the result of the whole team) is as follows: we determine the sum of the goals of all the players and find out how many percent of this number each football player scored. Round the value using
Math.round().
Let’s calculate what percentage the number is:
// Total value, that is 100%
1200
// How many percent is 225 from 1200
(225 * 100) / 1200 = 18.75
// After rounding with Math.round()
19When you are done, press Hey boss, here’s your program! in the console, and Muffin will call function getStatistics and test the results of your work. Good luck!
You’ve gone to a different page
Click inside the mini-browser to shift the focus onto this window.
To access the Objects challenges in the JavaScript programming, you need to sign up and subscribe first.
Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.
Forgot to connect your email to the profile? Email us and we’ll help.