Advertisement
ErolKZ

Untitled

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