Todorov_Stanimir

01. The Hunting Games Fundam.Mid Exam-10 March 2019 2 group

Jun 25th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function theHuntingGames(input) {
  2.     let daysOfAdventures = parseInt(input.shift());
  3.     let countOfPlayers = parseInt(input.shift());
  4.     let groupEnergy = parseFloat(input.shift());
  5.     let waterPerDayForOnePerson = parseFloat(input.shift());
  6.     let foodPerDayForOnePerson = parseFloat(input.shift());
  7.  
  8.     let totalWater = daysOfAdventures * countOfPlayers * waterPerDayForOnePerson;
  9.     let totalFood = daysOfAdventures * countOfPlayers * foodPerDayForOnePerson;
  10.     let theyHaveEnoughtEnergy = true;
  11.  
  12.     for (let i = 1; i <= daysOfAdventures; i++) {
  13.         let energyLoss = parseFloat(input.shift());
  14.        
  15.         if (groupEnergy-energyLoss <= 0) {
  16.            
  17.             theyHaveEnoughtEnergy = false;
  18.             break;
  19.         } else {
  20.             groupEnergy -= energyLoss;
  21.         }
  22.         if (i % 2 === 0) {
  23.             groupEnergy += 5 / 100 * groupEnergy;
  24.             totalWater -= 30 / 100 * totalWater;
  25.         }
  26.         if (i % 3 === 0) {
  27.             totalFood -= totalFood / countOfPlayers;
  28.             groupEnergy += 10 / 100 * groupEnergy;
  29.         }
  30.     }
  31.     if (theyHaveEnoughtEnergy === true) {
  32.         console.log(`You are ready for the quest. You will be left with - ${groupEnergy.toFixed(2)} energy!`)
  33.     } else {
  34.         console.log(`You will run out of energy. You will be left with ${totalFood.toFixed(2)} food and ${totalWater.toFixed(2)} water.`)
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment