-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtipCalculator
More file actions
74 lines (61 loc) · 2.03 KB
/
Copy pathtipCalculator
File metadata and controls
74 lines (61 loc) · 2.03 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
var john = {
bills : [124, 48, 268, 180, 42],
calcTip: function() {
this.tips = []
this.finalValue = []
for (var i = 0; i < this.bills.length; i++)
{
// calculate tipps
var percentage
var bill = this.bills[i]
if (bill < 50) {
percentage = .2
} else if (bill > 50 && bill < 200) {
percentage = .15
} else {
percentage = .1
}
this.tips[i] = bill * percentage
this.finalValue[i] = bill+ bill * percentage
}
}
}
var mark = {
bills : [77, 375, 110, 45],
calcTip: function() {
this.tips = []
this.finalValue = []
for (var i = 0; i < this.bills.length; i++)
{
// calculate tipps
var percentage
var bill = this.bills[i]
if (bill < 100) {
percentage = .2
} else if (bill > 100 && bill < 300) {
percentage = .1
} else {
percentage = .25
}
this.tips[i] = bill * percentage
this.finalValue[i] = bill+ bill * percentage
}
}
}
function calcAvg(tips) {
var sum = 0
for (var i = 0; i < tips.length; i++) {
sum = sum + tips[i]
}
return sum / tips.length;
}
john.calcTip()
mark.calcTip()
john.average = calcAvg(john.tips)
mark.average = calcAvg(mark.tips)
console.log(john,mark)
if (john.average > mark.average) {
console.log('John\'s family pays higher tips with an average of $' + john.average)
} else {
console.log('Mark\'s family pays higher tips with an average of $' + mark.average)
}