Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cruiseGames(input) {
- let gamer = input[0];
- let games = Number(input[1]);
- let volleyballGames = 0;
- let volleyballScores = 0;
- let tennisGames = 0;
- let tennisScores = 0;
- let badmintonGames = 0;
- let badmintonScores = 0;
- let index = 2;
- for (let i = 0; i < games; i++) {
- let game = input[index++];
- let score = Number(input[index++]);
- if (game == "volleyball") {
- volleyballGames++;
- volleyballScores += score * 1.07;
- } else if (game == "tennis") {
- tennisGames++;
- tennisScores += score * 1.05;
- } else {
- badmintonGames++;
- badmintonScores += score * 1.02;
- }
- }
- let averageVolleyballPoints = parseInt(volleyballScores / volleyballGames);
- let averageTennisPoints = parseInt(tennisScores / tennisGames);
- let averageBadmintonPoints = parseInt(badmintonScores / badmintonGames);
- let totalPoints = parseInt(volleyballScores + tennisScores + badmintonScores);
- if (averageVolleyballPoints >= 75 && averageTennisPoints >= 75 && averageBadmintonPoints >= 75) {
- console.log(`Congratulations, ${gamer}! You won the cruise games with ${totalPoints} points.`);
- } else {
- console.log(`Sorry, ${gamer}, you lost. Your points are only ${totalPoints}.`);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement