简体   繁体   English

为什么我得到楠

[英]Why i am getting Nan

Trying to calculate BMI using the following code:尝试使用以下代码计算 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);

But I'm getting Not a number error.但我得到Not a number错误。

I'm not sure what youre trying to achieve but you can try this:我不确定你想要达到什么目标,但你可以试试这个:

 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());

Property Weight should be weight and then you can call the method calcBMI() .属性权Weight应该是weight ,然后您可以调用方法calcBMI()

I'm showing you this approach as you've hard coded all the values.我正在向您展示这种方法,因为您已经对所有值进行了硬编码。 So, in this case it is pretty straight forward.因此,在这种情况下,它非常简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM