const john = {
firstName: "John",
lastName: "Smith",
mass: 92,
height: 1.95,
calcBMI: function() {
this.bmi = this.mass / (this.height ** 2);
return this.bmi;
}
};
console.log(john.bmi)
I get an undefined value, I'm confused because when my professor plugged it in, it returned the correct value it should have.
const john = {
firstName: "John",
lastName: "Smith",
mass: 92,
height: 1.95,
calcBMI: function() {
this.bmi = this.mass / (this.height ** 2);
return this.bmi;
}
};
john.calcBMI();
console.log(john.bmi)
You need to invoke the calcBMI function for there to be a property called bmi with a valid value ... Otherwise it would always return undefined.