Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let countDaysOfTournament = Number(input[0]);
- let gatheredMoneyForDay = 0;
- let allMoney = 0;
- let index = 2;
- let win = 0;
- let lose = 0;
- let winDays = 0;
- let loseDays = 0;
- for (let i = 1; i <= input.length; i++) {
- if (input[i] === 'win') {
- win++;
- gatheredMoneyForDay += 20;
- } else if (input[i] === 'lose') {
- lose++;
- }
- if (input[i] === 'Finish') {
- if (win > lose) {
- gatheredMoneyForDay = gatheredMoneyForDay + (gatheredMoneyForDay * (10 / 100));
- winDays++;
- } else if (lose > win) {
- loseDays++;
- }
- allMoney += gatheredMoneyForDay;
- gatheredMoneyForDay = 0;
- win = 0;
- lose = 0;
- }
- }
- if (winDays > loseDays) {
- allMoney = allMoney + (allMoney * (20 / 100));
- console.log(`You won the tournament! Total raised money: ${allMoney.toFixed(2)}`);
- } else {
- console.log(`You lost the tournament! Total raised money: ${allMoney.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement