Advertisement
dabidabidesh

Untitled

May 23rd, 2020
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //06. Tournament of Christmas
  2. function tournamentOfChristmas(arg) {
  3.  
  4.   let countDays = parseInt(arg.shift())
  5.  
  6.   let countTotalMoney = 0
  7.   let countTotalWin = 0
  8.   let countTotalLoose = 0
  9.   for (let i = 1; i <= countDays; i++) {
  10.  
  11.     let command = arg.shift()
  12.     let winGames = 0
  13.     let loseGames = 0
  14.     let countDaysMoney = 0
  15.     while (command != 'Finish') {
  16.  
  17.       let winOrLose = arg.shift()
  18.  
  19.       if (winOrLose == 'win') {
  20.         winGames++
  21.         countDaysMoney += 20
  22.       }
  23.  
  24.       else if (winOrLose == 'lose')
  25.         loseGames++
  26.  
  27.       command = arg.shift()
  28.     }
  29.     if (winGames > loseGames)
  30.       countDaysMoney *= 1.1
  31.  
  32.     countTotalMoney += countDaysMoney
  33.     countTotalWin += winGames
  34.     countTotalLoose += loseGames
  35.   }
  36.   if (countTotalWin > countTotalLoose) {
  37.  
  38.     countTotalMoney *= 1.2
  39.     console.log(`You won the tournament! Total raised money: ${countTotalMoney.toFixed(2)}`)
  40.   }
  41.   else
  42.     console.log(`You lost the tournament! Total raised money: ${countTotalMoney.toFixed(2)}`)
  43. }
  44.  
  45. tournamentOfChristmas(
  46.   [
  47.     '2',         'volleyball',
  48.     'win',       'football',
  49.     'lose',      'basketball',
  50.     'win',       'Finish',
  51.     'golf',      'win',
  52.     'tennis',    'win',
  53.     'badminton', 'win',
  54.     'Finish'
  55.   ]
  56.  
  57. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement