Advertisement
Liliana797979

viarno reshenie tournament

Feb 14th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function tournament(input) {
  4.     let index = 0;
  5.     let daysTournament = Number(input[index++]);
  6.     let charityMoney = 0;
  7.     let winCount = 0;
  8.     let loseCount = 0;
  9.  
  10.     for (let i = 0; i < daysTournament; i++) {
  11.  
  12.         let command = input[index++];
  13.         let tempCharityMoney = 0;
  14.         let tempWinCount = 0;
  15.         let tempLoseCount = 0;
  16.  
  17.         while (command !== "Finish") {
  18.             let result = input[index++];
  19.             if (result === "win") {
  20.                 tempCharityMoney += 20;
  21.                 tempWinCount++;
  22.             } else {
  23.                 tempLoseCount++;
  24.             }
  25.             command = input[index++]
  26.         }
  27.         if (tempWinCount > tempLoseCount) {
  28.             charityMoney += tempCharityMoney * 1.10;
  29.             winCount++
  30.         } else {
  31.             charityMoney += tempCharityMoney;
  32.             loseCount++;
  33.         }
  34.     }
  35.     if (winCount > loseCount) {
  36.         charityMoney *= 1.20;
  37.         console.log(`You won the tournament! Total raised money: ${charityMoney.toFixed(2)}`);
  38.     } else {
  39.         console.log(`You lost the tournament! Total raised money: ${charityMoney.toFixed(2)}`)
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement