Advertisement
Spocoman

Cruise Games

Oct 6th, 2023
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cruiseGames(input) {
  2.     let gamer = input[0];
  3.     let games = Number(input[1]);
  4.     let volleyballGames = 0;
  5.     let volleyballScores = 0;
  6.     let tennisGames = 0;
  7.     let tennisScores = 0;
  8.     let badmintonGames = 0;
  9.     let badmintonScores = 0;
  10.     let index = 2;
  11.  
  12.     for (let i = 0; i < games; i++) {
  13.         let game = input[index++];
  14.         let score = Number(input[index++]);
  15.  
  16.         if (game == "volleyball") {
  17.             volleyballGames++;
  18.             volleyballScores += score * 1.07;
  19.         } else if (game == "tennis") {
  20.             tennisGames++;
  21.             tennisScores += score * 1.05;
  22.         } else {
  23.             badmintonGames++;
  24.             badmintonScores += score * 1.02;
  25.         }
  26.     }
  27.  
  28.     let averageVolleyballPoints = parseInt(volleyballScores / volleyballGames);
  29.     let averageTennisPoints = parseInt(tennisScores / tennisGames);
  30.     let averageBadmintonPoints = parseInt(badmintonScores / badmintonGames);
  31.     let totalPoints = parseInt(volleyballScores + tennisScores + badmintonScores);
  32.  
  33.     if (averageVolleyballPoints >= 75 && averageTennisPoints >= 75 && averageBadmintonPoints >= 75) {
  34.         console.log(`Congratulations, ${gamer}! You won the cruise games with ${totalPoints} points.`);
  35.     } else {
  36.         console.log(`Sorry, ${gamer}, you lost. Your points are only ${totalPoints}.`);
  37.     }
  38.     return;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement