Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (99 loc) · 4.85 KB
/
Copy pathscript.js
File metadata and controls
149 lines (99 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//make sure the HTML file is fully loaded before we run our jQuery code.
$(document).ready(function () {
// -------------- Coffee Shop Costs
/*
#input1 -- cups of coffee per day
#input2 -- price for a cup of store bought coffee
#input3 -- price per lb for your favorite coffee
#input4 -- cost of coffee machine
#input5 -- cost of a box kerig pods
#input6 -- number of pods per box
*/
//
// attach click listener to the submit button.
$("#submit1").click(function () {
//when clicked, create a variable holding the value of the input text box.
console.log(typeof $("#input1").val());
// function call written into a variable and return results in the html
var yrCafecost = cafeCostyr($("#input2").val(), $("#input1").val());
$("#results1").html(yrCafecost);
});
//-----------------Home Brewed
$("#submit2").click(function () {
//when clicked, create a variable holding the value of the input text box.
console.log(typeof $("#input1").val());
// function call written into a variable and return results in the html
var yrHomecost = homeCostyr($("#input3").val(), $("#input1").val());
$("#results2").html(yrHomecost);
});
//------------------------- kerig refillable Brewed Below
$("#submit3").click(function () {
//when clicked, create a variable holding the value of the input text box.
console.log(typeof $("#input1").val());
// function call written into a variable and return results in the html
var yrKerigrcost = kerigrCostyr($("#input4").val(), $("#input1").val());
$("#results3").html(yrKerigrcost);
});
//--- Kerig Coffee Machine bought pods Below
$("#submit4").click(function () {
//when clicked, create a variable holding the value of the input text box.
console.log(typeof $("#input1").val());
// function call written into a variable and return results in the html
var yrKerigrcost = kerigpCostyr($("#input5").val(), $("#input6").val());
$("#results4").html(yrKerigrcost);
});
});
//--------------------------
function cafeCostyr(numCups, price) {
var dayCups = parseInt($("#input1").val());
var costPrcup = parseFloat($("#input2").val());
var storeBought;
var totcafe = 50 * 5 * dayCups * costPrcup;
storeBought = `Based on ${dayCups} cup(s) of coffee each day at a cost of $ ${costPrcup} per cup, you spend $ ${totcafe} each year for buying coffee from a coffee shop.`;
return storeBought
}
//-----------------------------
function homeCostyr(price, numCups) {
var dayCups = parseInt($("#input1").val());
var pricePerlb = parseInt($("#input3").val());
var homeBrewed;
var pressOrfilter = 20;
// based on recommended 14g of coffee per 8oz of water
var lbspertyr = dayCups * 14 * 50 * 5 / 454;
var lbsCoffeeyr = Math.ceil(lbspertyr);
var totHcafe = pressOrfilter + pricePerlb * lbsCoffeeyr;
homeBrewed = `Based on ${dayCups} cup(s) of coffee each day at a cost of $ ${pricePerlb} per pound for coffee, you spend $ ${totHcafe} each year if you made the coffee yourself.`;
return homeBrewed
}
//--------------- using refillable kerig filter and machine below
function kerigrCostyr(numCups, machineCost) {
var dayCups = parseInt($("#input1").val());
var pricePerlb = parseInt($("#input3").val());
var costOfmachine = parseInt($("#input4").val());
var kerigrBrewed;
var supplies = 15 + 10 + 10; // descaling=15,charcoal filter=10, reusable filter =10
// calculations based on prior cost of coffee and using 18g of coffee per refillable pod
var lbspertyr = dayCups * 18 * 50 * 5 / 454;
var lbsCoffeeyr = Math.ceil(lbspertyr);
var lbsCoffeeyr = Math.ceil(lbspertyr);
var totKrcafe = costOfmachine + supplies + pricePerlb * lbsCoffeeyr;
kerigrBrewed = `Based on ${dayCups} cup(s) of coffee each day at a cost of $ ${pricePerlb} per pound for coffee, you spend $ ${totKrcafe} each year if you made the coffee w refillable kerig.`;
return kerigrBrewed
}
//--------------- using kerig bought pods and machine below
function kerigpCostyr(numCups, machineCost) {
var dayCups = parseInt($("#input1").val());
var costOfmachine = parseInt($("#input4").val());
var pricePerbox = parseInt($("#input5").val());
var podsPerbox = parseInt($("#input6").val());
var kerigPodbrewed;
var supplies = 15 + 10; // descaling=15,charcoal filter=10, NO reusable filter
// calculations based on prior cost of coffee and using 18g of coffee per refillable pod
var pricePerpod = pricePerbox / podsPerbox;
// calculations 50 week year and 5 working days a week
var tCostofPods = dayCups * pricePerpod * 50 * 5;
var numb = costOfmachine + supplies + tCostofPods;
var totKPcafe = numb.toFixed(2);
kerigPodbrewed = `Based on ${dayCups} cup(s) of coffee each day at a cost of $ ${pricePerbox} per box of ${podsPerbox} pods , you spend $ ${totKPcafe} each year using Kerig and bought PODs.`;
return kerigPodbrewed
}