Advertisement
Liliana797979

viarno reshenie christmas tournement

Feb 21st, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. // 08. Tournament of Christmas
  3.  
  4. function solve(arg) {
  5.     let daysAll = Number(arg[0]);
  6.     let idx = 1;
  7.     let sport = "";
  8.     let text = "";
  9.     let moneyTotal = 0;
  10.     let winsTotal = 0;
  11.     for (let i = 1; i <= daysAll; i++) {
  12.         let winsPerDay = 0;
  13.         let moneyPerDay = 0;
  14.         while (true) {
  15.             command = arg[idx++];
  16.             if (command === "Finish") {
  17.                 break;
  18.             } else {
  19.                 sport = command;
  20.                 // console.log(`sport: ${sport}`);
  21.                 text = arg[idx++];
  22.                 // console.log(`text: ${text}`);
  23.             }
  24.             if (text === "win") {
  25.                 moneyPerDay += 20;
  26.                 winsPerDay++;
  27.             } else {
  28.                 winsPerDay--;
  29.             }
  30.             // console.log(`moneyPerDay now = ${moneyPerDay}`);
  31.         }
  32.         if (winsPerDay > 0) {
  33.             moneyPerDay *= 1.1;
  34.             winsTotal++;
  35.         } else {
  36.             winsTotal--;
  37.         }
  38.         moneyTotal += moneyPerDay;
  39.         // console.log(`Money after day ${i}: ${moneyPerDay}; winsPerDay = ${winsPerDay}`);
  40.         // console.log(`Money Total after day ${i}: ${moneyTotal}`);
  41.     }
  42.     if (winsTotal > 0) {
  43.         moneyTotal *= 1.2;
  44.         console.log(`You won the tournament! Total raised money: ${moneyTotal.toFixed(2)}`);
  45.     } else {
  46.         console.log(`You lost the tournament! Total raised money: ${moneyTotal.toFixed(2)}`);
  47.     }
  48.     // console.log(`Money Total at the end}: ${moneyTotal}`);
  49. }
  50.  
  51. solve(["2", "volleyball", "win", "football", "lose", "basketball", "win", "Finish",
  52. "golf", "win", "tennis", "win", "badminton", "win", "Finish"]) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement