-
Notifications
You must be signed in to change notification settings - Fork 0
/
coding challenge 7.js
36 lines (28 loc) · 1.39 KB
/
coding challenge 7.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
// coding challenge 7
let markDetails = {
MarkFullName: 'Mark Miller',
MarkMass: 78,
Markheight: 1.69,
calcBMIMark: function () {
let bMIValue = this.MarkMass / (this.Markheight ** 2)
this.bMI = bMIValue //Note new property created
return this.bMI
}
}
let johnDetails = {
JohnFullName: 'John Smith',
JohnMass: 92,
JohnHeight: 1.95,
calcJohnMark: function () {
let bMIValue1 = this.JohnMass / (this.JohnHeight ** 2)
this.bMI1 = bMIValue1 //Note new property created
return this.bMI1
}
}
console.log(markDetails.calcBMIMark())
console.log(johnDetails.calcJohnMark())
console.log(`${markDetails.MarkFullName}'s BMI(${markDetails.calcBMIMark()}) is greater than ${johnDetails.JohnFullName}'s BMI (${johnDetails['calcJohnMark']()}).`)
console.log(markDetails.bMI)
console.log(johnDetails.bMI1)
//what I am doing here is calling the markDetails's new property 'bMI' added using fucntion calcJohnMark. This works because calcJohnMark has already been invoked or called.
// console.log(`${markDetails.bMI > johnDetails.bMI1 ? `${markDetails.MarkFullName}'s BMI(${markDetails.calcBMIMark()}) is greater than ${johnDetails.JohnFullName}'s BMI (${johnDetails['calcJohnMark']()})` : `${markDetails.MarkFullName}'s BMI(${markDetails.calcBMIMark()}) is less than ${johnDetails.JohnFullName}'s BMI (${johnDetails.calcJohnMark()})`}`) // Using Ternery operator inside template literal