Advertisement
Spocoman

Tournament of Christmas

Feb 24th, 2022 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tournamentOfChristmas(input) {
  2.     let index = 0,
  3.         winTotal = 0,
  4.         loseTotal = 0,
  5.         sumTotal = 0,
  6.         days = Number(input[index++]);
  7.    
  8.     for (let i = 0; i < days; i++) {
  9.         let command = input[index++];
  10.         let win = 0, lose = 0, sum = 0;
  11.  
  12.         while (command !== "Finish") {
  13.             if (command === "win") {
  14.                 sum += 20;
  15.                 win++;
  16.             } else if (command === "lose") {
  17.                 lose++;
  18.             }
  19.             command = input[index++];
  20.         }
  21.  
  22.         if (win > lose) {
  23.             sumTotal += sum * 1.1;
  24.             winTotal += win;
  25.         } else {
  26.             sumTotal += sum;
  27.             loseTotal += lose;
  28.         }
  29.     }
  30.  
  31.     if (winTotal > loseTotal) {
  32.         console.log(`You won the tournament! Total raised money: ${(sumTotal * 1.2).toFixed(2)}`);
  33.     } else {
  34.         console.log(`You lost the tournament! Total raised money: ${sumTotal.toFixed(2)}`);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement