ExGiX

tournament

Mar 30th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. function tournamet (input) {
  2.  
  3. let days = Number(input.shift());
  4.  
  5. let totalMoney = 0;
  6. let winDays = 0;
  7. let loseDays = 0;
  8. let totalSum = 0;
  9.  
  10.  
  11. for(let i = 0; i < days; i++) { // 3
  12. let sport = input.shift();
  13. let wins = 0;
  14. let loses = 0;
  15. let sum = 0;
  16.  
  17. while(sport !== 'Finish') {
  18. let reuslt = input.shift();
  19.  
  20. if(reuslt == 'win') {
  21. sum += 20;
  22. totalSum += sum
  23. wins++;
  24. winDays++;
  25.  
  26. }
  27.  
  28. if(reuslt == 'lose') {
  29. loses++;
  30. loseDays++;
  31. }
  32.  
  33. sport = input.shift();
  34. }
  35.  
  36.  
  37. if(wins > loses) {
  38. sum = sum * 1.10;
  39. totalMoney += sum;
  40.  
  41. }
  42.  
  43. }
  44.  
  45. if(winDays > loseDays) {
  46. totalMoney = totalMoney * 1.20;
  47. console.log(`You won the tournament! Total raised money: ${totalMoney.toFixed(2)}`)
  48.  
  49. } else {
  50. console.log(`You lost the tournament! Total raised money: ${totalMoney.toFixed(2)}`)
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment