Advertisement
ErolKZ

Untitled

Jul 10th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. function solve(input) {
  2.  
  3.  
  4. let countDaysOfTournament = Number(input[0]);
  5.  
  6. let gatheredMoneyForDay = 0;
  7.  
  8. let allMoney = 0;
  9.  
  10. let index = 2;
  11.  
  12. let win = 0;
  13.  
  14. let lose = 0;
  15.  
  16. let winDays = 0;
  17.  
  18. let loseDays = 0;
  19.  
  20.  
  21.  
  22.  
  23.  
  24. for (let i = 1; i <= input.length; i++) {
  25.  
  26.  
  27.  
  28.  
  29. if (input[i] === 'win') {
  30.  
  31. win++;
  32.  
  33. gatheredMoneyForDay += 20;
  34.  
  35. } else if (input[i] === 'lose') {
  36.  
  37. lose++;
  38.  
  39. }
  40.  
  41.  
  42. if (input[i] === 'Finish') {
  43.  
  44.  
  45. if (win > lose) {
  46.  
  47. gatheredMoneyForDay = gatheredMoneyForDay + (gatheredMoneyForDay * (10 / 100));
  48.  
  49. winDays++;
  50.  
  51. } else if (lose > win) {
  52.  
  53. loseDays++;
  54.  
  55. }
  56.  
  57. allMoney += gatheredMoneyForDay;
  58.  
  59. gatheredMoneyForDay = 0;
  60.  
  61. win = 0;
  62.  
  63. lose = 0;
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. }
  76.  
  77.  
  78. if (winDays > loseDays) {
  79.  
  80. allMoney = allMoney + (allMoney * (20 / 100));
  81.  
  82. console.log(`You won the tournament! Total raised money: ${allMoney.toFixed(2)}`);
  83.  
  84. } else {
  85.  
  86. console.log(`You lost the tournament! Total raised money: ${allMoney.toFixed(2)}`);
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement