TZinovieva

Tournament of Christmas

Jan 7th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tournamentOfChristmas(input) {
  2.     let days = Number(input[0]);
  3.  
  4.     let index = 1;
  5.     let command = input[index];
  6.     index++;
  7.  
  8.    
  9.     let totalMoney = 0;
  10.     let dayWon = 0;
  11.     let dayLost = 0;
  12.     for (let i = 0; i < days; i++) {
  13.    
  14.         let gameWon = 0;
  15.         let gameLost = 0;
  16.         let raisedMoney = 0;
  17.         while (command !== "Finish") {
  18.             let sport = command;
  19.             let result = input[index];
  20.             index++;
  21.  
  22.             if (result === "win") {
  23.                 gameWon++;
  24.                 raisedMoney += 20;
  25.             } else {
  26.                 gameLost++;
  27.             }
  28.             command = input[index];
  29.             index++;
  30.             }  
  31.             if (gameWon > gameLost) {
  32.                 dayWon++;
  33.                 raisedMoney += raisedMoney * 0.10;
  34.             } else {
  35.                 dayLost++;
  36.             }
  37.             totalMoney += raisedMoney;
  38.             if (command === "Finish") {
  39.  
  40.                 command = input[index];
  41.                 index++;
  42.             }
  43.     }
  44.     if (dayWon > dayLost) {
  45.         totalMoney += totalMoney * 0.20;
  46.         console.log(`You won the tournament! Total raised money: ${totalMoney.toFixed(2)}`);
  47.     } else {
  48.         console.log(`You lost the tournament! Total raised money: ${totalMoney.toFixed(2)}`);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment