I'm trying to use an existing function inside an object.
So far, all the answers I have seen focused on creating a new function inside an object, but I want to use an existing function inside an object. However, I am getting NaN as the output when I call the property name of the object.
The minimal reproducible code for my output is this:
function bmiCalculator(weight, height) {
bmi = weight/(height**2)
return bmi;
}
var markDetails = {
name: "Mark",
weight: 70,
height: 175,
bmi: bmiCalculator(this.weight,this.height),
error: console.log(this.weight)
};
console.log(markDetails)
The problem seems to lie with the this.weight and this.height object definitions because they return NaN when I console.log(this.weight). But, I don't know exactly what went wrong