In this exercise, you are implementing a way to keep track of the high scores for the most popular game in your local arcade hall.
You have 5 functions to implement, mostly related to manipulating an object that holds high scores.
Create a function createScoreBoard that creates an object that serves as a high score board.
The keys of this object will be the names of the players, the values will be their scores.
For testing purposes, you want to directly include one entry in the object.
This initial entry should consist of The Best Ever as player name and 1000000 as score.
createScoreBoard();
// returns an object with one initial entryTo add a player to the high score board, define the function addPlayer.
It accepts 3 parameters:
The function returns the same score board object that was passed in after adding the new player.
addPlayer({ 'Dave Thomas': 0 }, 'José Valim', 486373);
// => {'Dave Thomas': 0, 'José Valim': 486373}If players violate the rules of the arcade hall, they are manually removed from the high score board.
Define removePlayer which takes 2 parameters:
This function should remove the entry for the given player from the board and return the board afterwards. If the player was not on the board in the first place, nothing should happen to the board. It should be returned as is.
removePlayer({ 'Dave Thomas': 0 }, 'Dave Thomas');
// => {}
removePlayer({ 'Dave Thomas': 0 }, 'Rose Fanaras');
// => { 'Dave Thomas': 0 }If a player finishes another game at the arcade hall, a certain amount of points will be added to the previous score on the board.
Implement updateScore, which takes 3 parameters:
The function should return the score board after the update was done.
updateScore({ 'Freyja Ćirić': 12771008 }, 'Freyja Ćirić', 73);
// => {"Freyja Ćirić", 12771081}The arcade hall keeps a separate score board on Mondays. At the end of the day, each player on that board gets 100 additional points.
Implement the function applyMondayBonus that accepts a score board.
The function adds the bonus points for each player that is listed on that board.
Afterwards, the board is returned.
const scoreBoard = {
'Dave Thomas': 44,
'Freyja Ćirić': 539,
'José Valim': 265,
};
applyMondayBonus(scoreBoard);
// => { 'Dave Thomas': 144, 'Freyja Ćirić': 639, 'José Valim': 365 }In this exercise, you are implementing a way to keep track of the high scores for the most popular game in your local arcade hall.
You have 5 functions to implement, mostly related to manipulating an object that holds high scores.
Create a function createScoreBoard that creates an object that serves as a high score board.
The keys of this object will be the names of the players, the values will be their scores.
For testing purposes, you want to directly include one entry in the object.
This initial entry should consist of The Best Ever as player name and 1000000 as score.
createScoreBoard();
// returns an object with one initial entryTo add a player to the high score board, define the function addPlayer.
It accepts 3 parameters:
The function returns the same score board object that was passed in after adding the new player.
addPlayer({ 'Dave Thomas': 0 }, 'José Valim', 486373);
// => {'Dave Thomas': 0, 'José Valim': 486373}If players violate the rules of the arcade hall, they are manually removed from the high score board.
Define removePlayer which takes 2 parameters:
This function should remove the entry for the given player from the board and return the board afterwards. If the player was not on the board in the first place, nothing should happen to the board. It should be returned as is.
removePlayer({ 'Dave Thomas': 0 }, 'Dave Thomas');
// => {}
removePlayer({ 'Dave Thomas': 0 }, 'Rose Fanaras');
// => { 'Dave Thomas': 0 }If a player finishes another game at the arcade hall, a certain amount of points will be added to the previous score on the board.
Implement updateScore, which takes 3 parameters:
The function should return the score board after the update was done.
updateScore({ 'Freyja Ćirić': 12771008 }, 'Freyja Ćirić', 73);
// => {"Freyja Ćirić", 12771081}The arcade hall keeps a separate score board on Mondays. At the end of the day, each player on that board gets 100 additional points.
Implement the function applyMondayBonus that accepts a score board.
The function adds the bonus points for each player that is listed on that board.
Afterwards, the board is returned.
const scoreBoard = {
'Dave Thomas': 44,
'Freyja Ćirić': 539,
'José Valim': 265,
};
applyMondayBonus(scoreBoard);
// => { 'Dave Thomas': 144, 'Freyja Ćirić': 639, 'José Valim': 365 }