forked from hellojs-tw/js-201-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
31 lines (30 loc) · 848 Bytes
/
sample.js
File metadata and controls
31 lines (30 loc) · 848 Bytes
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
var BMICalculator = {
height: 0,
weight: 0,
bmi: 0,
calc: function(height, weight){
this.height = height || 155;
this.weight = weight || 40;
this.bmi = this.weight / Math.pow((this.height / 100), 2);
},
getBMI: function(){
return this.bmi;
},
getAdvice: function(user){
var bmi = this.bmi;
var firstname = user.firstname;
var lastname = user.lastname;
console.log(firstname, lastname);
if (bmi < 18.5) {
console.log('體重過輕');
} else if(18.5 <= bmi && bmi < 24) {
console.log('正常範圍');
} else {
console.log('異常範圍');
}
}
};
var myApp = Object.create(BMICalculator);
myApp.calc(155, 52);
myApp.getBMI();
myApp.getAdvice({firstname: 'ailin', lastname: 'liou'});