Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tournament(input) {
- let index = 0;
- let daysTournament = Number(input[index++]);
- let charityMoney = 0;
- let winCount = 0;
- let loseCount = 0;
- for (let i = 0; i < daysTournament; i++) {
- let command = input[index++];
- let tempCharityMoney = 0;
- let tempWinCount = 0;
- let tempLoseCount = 0;
- while (command !== "Finish") {
- let result = input[index++];
- if (result === "win") {
- tempCharityMoney += 20;
- tempWinCount++;
- } else {
- tempLoseCount++;
- }
- command = input[index++]
- }
- if (tempWinCount > tempLoseCount) {
- charityMoney += tempCharityMoney * 1.10;
- winCount++
- } else {
- charityMoney += tempCharityMoney;
- loseCount++;
- }
- }
- if (winCount > loseCount) {
- charityMoney *= 1.20;
- console.log(`You won the tournament! Total raised money: ${charityMoney.toFixed(2)}`);
- } else {
- console.log(`You lost the tournament! Total raised money: ${charityMoney.toFixed(2)}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement