Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. //adding a couple functions to Global Scope
  2.  
  3. function myRandomNum(min,max){
  4. return Math.floor(Math.random()*(max-min+1)+min);
  5. };
  6.  
  7.  
  8. //Now I will use the random number I have generated above for the random customers per hour.
  9. function getCustPerHour(hours, min, max)
  10. { var custPerHour = new Array(hours);
  11. for (var index =0; index < hours; index++){
  12. custPerHour[index] = myRandomNum(min,max);
  13. }
  14.  
  15. return custPerHour;
  16.  
  17. };
  18. //Bake per hour function
  19.  
  20. function getDonpHr(cust, donuts)
  21. {
  22. var donpHr = new Array(cust);
  23. for (var index = 0; index<cust.length; index++)
  24. {
  25. donpHr[index] = Math.ceil(donuts * cust[index]);
  26. }
  27. return donpHr;
  28. };
  29.  
  30. //Now the we know how many donuts to make per hour, let's add them up to get the daily total.
  31.  
  32. function getTotal(donuts){
  33. var donsPerDay = 0;
  34. for (var index = 0; index < donuts.length; index++){
  35. donsPerDay += donuts[index];
  36. }
  37. return donsPerDay;
  38. };
  39.  
  40.  
  41.  
  42. //setting up my Shop Object
  43. function Shop(location, hours, custSlow, custRush, avgSale, avgCust, donpHr, dailyProduction)
  44. {
  45. this.location = location;
  46. this.hours = hours;
  47. this.custSlow = custSlow; //minimum customers per hour (slow hour)
  48. this.custRush = custRush; //maximum customers per hour (rush hour)
  49. this.avgSale = avgSale;
  50.  
  51. //use the random function and the slow/rush parameters to calculate the random customers
  52. this.avgCust = getCustPerHour(this.hours, this.custSlow, this.custRush);
  53. console.log(this.location + ", Customers per hour: " + this.avgCust);
  54.  
  55. //Donuts to bake per hour:
  56. this.donpHour = getDonpHr(this.avgCust, this.avgSale)
  57. console.log(this.location + ", Donuts to bake per hour: " + this.donPerHr);
  58.  
  59. //Daily donut production:
  60. this.dailyProduction = getTotal(this.donPerHour)
  61. console.log(this.location + ", Daily Production of Donuts: " + this.donutsPerDay);
  62.  
  63. };
  64.  
  65.  
  66.  
  67. //building all my shops
  68. var downtown = new Shop('Downtown', 8, 8, 48, 4.25);
  69. var capitolHill = new Shop('Capitol Hill', 24, 4, 37, 2.00);
  70. var southLakeUnion = new Shop('South Lake Union', 10, 9, 23, 6.33);
  71. var wedgewood = new Shop('Wedgewood', 7, 2, 28, 1.25);
  72. var ballard = new Shop('Ballard', 10, 8, 58, 3.75);
  73.  
  74. //console.log(myRandomNum(8,100) + " oh, hey");
  75. //console.log(getCustPerHour(8,3,40)+ " hello there");
  76. console.log(donPerHour());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement