so im doing a object exercise about 2 guys and i have to calculte their BMI. my code is like this:
const mark = {
firstName: "Mark",
lastName: "Miller",
Mass: "78 kg",
Height: "1.69 m",
calcBMI: function () {
return (
this.Mass / this.Height ** 2 - this.Mass / (this.Height * this.Height)
);
},
};
const john = {
firstName: "John",
lastName: "Smith",
Mass: "92 kg",
Height: "1.95 m",
calcBMI: function () {
return (
this.Mass / this.Height ** 2 - this.Mass / (this.Height * this.Height)
);
},
};
if (john.calcBMI > mark.calcBMI) {
console.log(
`${john.firstName} has a BMI of ${john.calcBMI} which is higher than ${
mark.firstName
} who has a BMI of ${mark.calcBMI()}`
);
} else {
console.log(
`${mark.firstName} has a BMI of ${mark.calcBMI} which is higher than ${
john.firstName
} who has a BMI of ${john.calcBMI()}`
);
}
the problem is the "this"? im having a problem with calcBMI function which its not doing the calculations of BMI