为什么我得到南
Why i am getting Nan
正在尝试使用以下代码计算 BMI:
var mark = {
fullName: 'John Cartor',
Weight : 90,
height : 1.59,
calcBMI: function(){
this.bmi= this.weight / (this.height* this.height);
return this.bmi;
}
};
john.calcBMI();
mark.calcBMI();
console.log(john, mark);
但是我遇到 Not a number
错误。
我不确定你想要达到什么目的,但你可以试试这个:
var mark = {
fullName: 'John Cartor',
weight : 90,
height : 1.59,
calcBMI: function(){
this.bmi= this.weight / (this.height* this.height);
return this.bmi;
}
};
console.log(mark.calcBMI());
属性 Weight
应该是 weight
然后你可以调用方法 calcBMI()
.
我向您展示了这种方法,因为您已经对所有值进行了硬编码。所以,在这种情况下,它非常简单。
正在尝试使用以下代码计算 BMI:
var mark = {
fullName: 'John Cartor',
Weight : 90,
height : 1.59,
calcBMI: function(){
this.bmi= this.weight / (this.height* this.height);
return this.bmi;
}
};
john.calcBMI();
mark.calcBMI();
console.log(john, mark);
但是我遇到 Not a number
错误。
我不确定你想要达到什么目的,但你可以试试这个:
var mark = {
fullName: 'John Cartor',
weight : 90,
height : 1.59,
calcBMI: function(){
this.bmi= this.weight / (this.height* this.height);
return this.bmi;
}
};
console.log(mark.calcBMI());
属性 Weight
应该是 weight
然后你可以调用方法 calcBMI()
.
我向您展示了这种方法,因为您已经对所有值进行了硬编码。所以,在这种情况下,它非常简单。