Advertisement
dimipan80

The Lifetime Supply Calculator

Nov 9th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Write a JavaScript function calcSupply(age, maxAge, food, foodPerDay) that accepts the following parameters:
  2. your age (years), your maximum age (years), your favorite food name (e.g. "chocolate"),
  3. estimate amount of your favorite food per day (a number). The function calculates how many of the food
  4. you will eat for the rest of your life. Write JS program lifetimeSupplyCalc.js that calculates
  5. the amount of a few foods that you will eat. The result should be printed on the console. */
  6.  
  7. "use strict";
  8.  
  9. function calcSupply(age, maxAge, food, foodPerDay) {
  10.     var totalAmmount = (maxAge - age) * foodPerDay * 365;
  11.     console.log(totalAmmount + 'kg of ' + food + ' would be enough until I am ' + maxAge + ' years old.');
  12. }
  13.  
  14. calcSupply(38, 118, 'chocolate', 0.5);
  15. calcSupply(20, 87, 'fruits', 2);
  16. calcSupply(16, 102, 'nuts', 1.1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement