Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //06. Tournament of Christmas
- function tournamentOfChristmas(arg) {
- let countDays = parseInt(arg.shift())
- let countTotalMoney = 0
- let countTotalWin = 0
- let countTotalLoose = 0
- for (let i = 1; i <= countDays; i++) {
- let command = arg.shift()
- let winGames = 0
- let loseGames = 0
- let countDaysMoney = 0
- while (command != 'Finish') {
- let winOrLose = arg.shift()
- if (winOrLose == 'win') {
- winGames++
- countDaysMoney += 20
- }
- else if (winOrLose == 'lose')
- loseGames++
- command = arg.shift()
- }
- if (winGames > loseGames)
- countDaysMoney *= 1.1
- countTotalMoney += countDaysMoney
- countTotalWin += winGames
- countTotalLoose += loseGames
- }
- if (countTotalWin > countTotalLoose) {
- countTotalMoney *= 1.2
- console.log(`You won the tournament! Total raised money: ${countTotalMoney.toFixed(2)}`)
- }
- else
- console.log(`You lost the tournament! Total raised money: ${countTotalMoney.toFixed(2)}`)
- }
- tournamentOfChristmas(
- [
- '2', 'volleyball',
- 'win', 'football',
- 'lose', 'basketball',
- 'win', 'Finish',
- 'golf', 'win',
- 'tennis', 'win',
- 'badminton', 'win',
- 'Finish'
- ]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement