coding challenge #3
const markObj = {
fullName: 'Mark Miller',
mass: 78,
height: 1.69,
calcBMI: function () {
this.bmi = this.mass / this.height ** 2;
return this.bmi;
}
}
const johnObj = {
fullName: 'John Smith',
mass: 92,
height: 1.95,
calcBMI: function () {
this.bmi = this.mass / this.height ** 2;
return this.bmi;
}
}
markObj.calcBMI(); // invoking the calcBMI method inside markObj
johnObj.calcBMI(); // // invoking the calcBMI method inside johnObj
console.log(markObj.bmi, johnObj.bmi); //now since bmi is a property of both the object we
can access it using dot or bracket notation.
if (markObj.bmi > johnObj.bmi) {
console.log(`${markObj.fullName}'s BMI (${markObj.bmi}) is higher than
${johnObj.fullName}'s BMI (${johnObj.bmi})`)
}
else if (johnObj.bmi > markObj.bmi) {
console.log(`${johnObj.fullName}'s BMI (${johnObj.bmi}) is higher than
${markObj.fullName}'s BMI (${markObj.bmi})`)
}


Comments
Post a Comment