Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let name = input.shift();
  4.     let playingGames = Number(input.shift());
  5.  
  6.      
  7.     let pointVoleyball = 0;
  8.     let counterVoleyball = 0;
  9.  
  10.     let pointTennis = 0;
  11.     let counterTennis = 0;
  12.  
  13.     let pointBadminton = 0;
  14.     let counterBadminton = 0;
  15.  
  16.     let totalPoint = 0;
  17.  
  18.     for (let i = 0; i < playingGames; i++) {
  19.        
  20.         let nameGame = input.shift();
  21.         let countPoints = Number(input.shift());
  22.        
  23.        switch (nameGame) {
  24.            case "Voleyball":
  25.            countPoints = countPoints * 1.07;
  26.            counterVoleyball++;
  27.            pointVoleyball += countPoints;
  28.            
  29.            break;
  30.  
  31.            case "Tennis":
  32.            countPoints = countPoints * 1.05;
  33.            counterTennis++;
  34.            pointTennis += countPoints;
  35.            
  36.            break;
  37.  
  38.            case "Badminton":
  39.            countPoints = countPoints * 1.02;
  40.            counterBadminton++;
  41.            pointBadminton += countPoints;
  42.                      
  43.            break;
  44.        }
  45.  
  46.         totalPoint += countPoints;
  47.      
  48.     }
  49.        let totalVoley = Math.floor(pointVoleyball/counterVoleyball);
  50.        let totalTennis = Math.floor(pointTennis/counterTennis);
  51.        let totalBadminton = Math.floor(pointBadminton/counterBadminton);
  52.  
  53.     if (totalVoley >= 75 && totalTennis >= 75 && totalBadminton >= 75) {
  54.  
  55.         console.log(`Congratulations, ${name}! You won the cruise games with ${Math.floor(totalPoint)} points.`)
  56.     } else {
  57.         console.log(`Sorry, ${name}, you lost. Your points are only ${Math.floor(totalPoint)}.`)
  58.     }  
  59.  
  60. }
  61.  
  62. solve(["Pepi",
  63.     "3",
  64.     "volleyball",
  65.     "78",
  66.     "tennis",
  67.     "98",
  68.     "badminton",
  69.     "105"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement