Advertisement
gogio8

01.The Hunting Games

Feb 19th, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. function theHuntingGame(input){
  2. let daysOfTheAndventure = Number(input.shift());
  3. let numberOfPlayers = Number(input.shift());
  4. let totalEnergy = Number(input.shift());
  5. let waterForOne = Number(input.shift());
  6. let foodForOne = Number(input.shift());
  7. let totalWater = waterForOne * numberOfPlayers * input.length;
  8. let totalFood = foodForOne * numberOfPlayers * input.length;
  9.  
  10. let needEnergyArr = input;
  11. let waterDay = 0;
  12. let foodDay = 0;
  13.  
  14. for (let i = 0; i < daysOfTheAndventure; i++){
  15. totalEnergy -= Number(needEnergyArr[i]);
  16.  
  17. if (totalEnergy <= 0){
  18. break;
  19. }
  20. waterDay++;
  21.  
  22. if (waterDay >= 2){
  23. totalEnergy += totalEnergy * 0.05;
  24. totalWater *= 0.7;
  25. waterDay = 0;
  26. }
  27. foodDay++;
  28. if (foodDay >= 3){
  29. totalFood -= (totalFood / numberOfPlayers);
  30. totalEnergy += totalEnergy * 0.1;
  31. foodDay = 0;
  32. }
  33.  
  34.  
  35. }
  36.  
  37. if (totalEnergy >= 1) {
  38. console.log(`You are ready for the quest. You will be left with - ${totalEnergy.toFixed(2)} energy!`);
  39. } else{
  40. console.log(`You will run out of energy. You will be left with ${totalFood.toFixed(2)} food and ${totalWater.toFixed(2)} water.`);
  41. }
  42.  
  43.  
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement