Advertisement
desito07

Harvest

Apr 1st, 2020
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function harvest(input) {
  2. let areaWineYard = +input.shift();
  3. let grapesPerM = +input.shift();
  4. let wineLitres = +input.shift();
  5. let count = +input.shift();
  6.  
  7. let grapesNeeded = areaWineYard * grapesPerM;
  8. let wineNeeded = (0.4 * grapesNeeded) / 2.5;
  9.  
  10. let diff = Math.trunc(wineNeeded - wineLitres);
  11. if (wineNeeded >= wineLitres) {
  12. if (diff) {
  13. diff / count;
  14. }
  15. console.log(`Good harvest this year! Total wine: ${wineNeeded} liters.`);
  16. console.log(`${diff} liters left -> ${diff / count} liters per person.`);
  17. } else {
  18. console.log(
  19. `It will be a tough winter! More ${Math.abs(diff).toFixed(
  20. 0
  21. )} liters wine needed.`
  22. );
  23. }
  24. }
  25. harvest(["650", "2", "175", "3"]);
  26. harvest(["1020", "1.5", "425", "4"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement