-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscript.js
60 lines (44 loc) · 1.49 KB
/
script.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
50
51
52
53
54
55
56
57
58
59
60
/* ## Coding Challenge 3
Let's go back to Mark and John comparing their BMIs!
This time, let's use objects to implement the calculations!
### Remember
`BMI = mass / height **2 = mass / (height * height).`
Mass in `kg` and height in `meter`.
1. For each of them, create an object with properties for their full name, mass, and height (Mark Miller and John Smith).✅
2. Create a `calcBMI` method on each object to calculate the `BMI` (the same method on both objects). Store the `BMI` value to a property, and also return it from the method.
3. Log to the console who has the higher BMI, together with the full name and the respective BMI.
### Example:
`"John Smith's BMI (28.3) is higher than Mark Miller's (23.9)!"`
### Test Data:
Marks weighs `78kg` and is `1.69m` tall. John weighs `92kg` and is `1.95m` tall.
Gooluck 😁
*/
const mark = {
fullName: "Mark Miller",
mass: 78,
height: 1.69,
calcBMI: function () {
this.bmi = this.mass / (this.height * this.height);
return this.bmi;
},
};
console.log(mark.calcBMI());
const john = {
fullName: "John Smith",
mass: 92,
height: 1.95,
calcBMI: function () {
this.bmi = this.mass / (this.height * this.height);
return this.bmi;
},
};
console.log(john.calcBMI());
if (mark.bmi > john.bmi) {
console.log(
`${mark.fullName}'s BMI ${mark.bmi} is higher than ${john.fullName}'s BMI ${john.bmi}!`
);
} else {
console.log(
`${john.fullName}'s BMI ${john.bmi} is higher than ${mark.fullName}'s BMI ${mark.bmi}!`
);
}