Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tournamentOfChristmas(input) {
- let days = Number(input[0]);
- let index = 1;
- let command = input[index];
- index++;
- let totalMoney = 0;
- let dayWon = 0;
- let dayLost = 0;
- for (let i = 0; i < days; i++) {
- let gameWon = 0;
- let gameLost = 0;
- let raisedMoney = 0;
- while (command !== "Finish") {
- let sport = command;
- let result = input[index];
- index++;
- if (result === "win") {
- gameWon++;
- raisedMoney += 20;
- } else {
- gameLost++;
- }
- command = input[index];
- index++;
- }
- if (gameWon > gameLost) {
- dayWon++;
- raisedMoney += raisedMoney * 0.10;
- } else {
- dayLost++;
- }
- totalMoney += raisedMoney;
- if (command === "Finish") {
- command = input[index];
- index++;
- }
- }
- if (dayWon > dayLost) {
- totalMoney += totalMoney * 0.20;
- console.log(`You won the tournament! Total raised money: ${totalMoney.toFixed(2)}`);
- } else {
- console.log(`You lost the tournament! Total raised money: ${totalMoney.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment