-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodingChallenge.js
50 lines (48 loc) · 1.38 KB
/
CodingChallenge.js
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
var john = {
Fname: 'johnM',
bills: [124,48,264,180,42],
calcTips: function(){
this.tips = [];
this.finalValues = [];
// tip calculation
for(var i = 0; i < this.bills.length; i++)
{
var prcnt;
var bill = this.bills[i];
if (bill < 50)
{prcnt = 0.2;}
else if (bill >= 50 && bill <= 200)
{prcnt = 0.15; }
else
{prcnt = 0.1;}
// adding result in array
this.tips[i] = prcnt * bill;
this.finalValues[i] = bill + bill*prcnt;
}
}
};
//console.log(john.calcTips()); this will give undefined
john.calcTips();
console.log(john);
var MarkCL = {
Fname: 'MarkCL',
bills: [124, 48, 264, 180, 42],
calcTips: function () {
this.tips = [];
this.finalValues = [];
// tip calculation
for (var i = 0; i < this.bills.length; i++) {
var prcnt;
var bill = this.bills[i];
if (bill < 50) { prcnt = 0.2; }
else if (bill >= 50 && bill <= 200) { prcnt = 0.15; }
else { prcnt = 0.1; }
// adding result in array
this.tips[i] = prcnt * bill;
this.finalValues[i] = bill + bill * prcnt;
}
}
};
//console.log(john.calcTips()); this will give undefined
MarkCL.calcTips();
console.log(MarkCL);