Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function theHuntingGames(input) {
- let daysOfAdventures = parseInt(input.shift());
- let countOfPlayers = parseInt(input.shift());
- let groupEnergy = parseFloat(input.shift());
- let waterPerDayForOnePerson = parseFloat(input.shift());
- let foodPerDayForOnePerson = parseFloat(input.shift());
- let totalWater = daysOfAdventures * countOfPlayers * waterPerDayForOnePerson;
- let totalFood = daysOfAdventures * countOfPlayers * foodPerDayForOnePerson;
- let theyHaveEnoughtEnergy = true;
- for (let i = 1; i <= daysOfAdventures; i++) {
- let energyLoss = parseFloat(input.shift());
- if (groupEnergy-energyLoss <= 0) {
- theyHaveEnoughtEnergy = false;
- break;
- } else {
- groupEnergy -= energyLoss;
- }
- if (i % 2 === 0) {
- groupEnergy += 5 / 100 * groupEnergy;
- totalWater -= 30 / 100 * totalWater;
- }
- if (i % 3 === 0) {
- totalFood -= totalFood / countOfPlayers;
- groupEnergy += 10 / 100 * groupEnergy;
- }
- }
- if (theyHaveEnoughtEnergy === true) {
- console.log(`You are ready for the quest. You will be left with - ${groupEnergy.toFixed(2)} energy!`)
- } else {
- console.log(`You will run out of energy. You will be left with ${totalFood.toFixed(2)} food and ${totalWater.toFixed(2)} water.`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment