Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tournamentOfChristmas(input) {
- let index = 0,
- winTotal = 0,
- loseTotal = 0,
- sumTotal = 0,
- days = Number(input[index++]);
- for (let i = 0; i < days; i++) {
- let command = input[index++];
- let win = 0, lose = 0, sum = 0;
- while (command !== "Finish") {
- if (command === "win") {
- sum += 20;
- win++;
- } else if (command === "lose") {
- lose++;
- }
- command = input[index++];
- }
- if (win > lose) {
- sumTotal += sum * 1.1;
- winTotal += win;
- } else {
- sumTotal += sum;
- loseTotal += lose;
- }
- }
- if (winTotal > loseTotal) {
- console.log(`You won the tournament! Total raised money: ${(sumTotal * 1.2).toFixed(2)}`);
- } else {
- console.log(`You lost the tournament! Total raised money: ${sumTotal.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement