我无法使此代码正确运行。它说我在以“ myBmiCalc”开头的行上有一个意外的标识符。
如果我摆脱了添加的myBmiCalc函数,则第一个输出语句有效,但我需要使用来自person对象的数据来计算BMI。
<head>
<title>Person object and BMI calculator</title>
</head>
<body>
<center>
<h2>My BMI Calculator</h2>
<p id="person"> </p>
<p id="myBmi"> </p>
<script>
let person ={
firstName : "Dave",
lastName : "Rand",
height: 58,
weight: 150,
personScript : function() {
return (this.firstName + " " + this.lastName + " is " + this.height + " inches tall " + " and weighs " + this.weight + " pounds");
}
myBmiCalc : function() {
return("And, his BMI is " + (weight/(height*height)*703));
}
};
document.getElementById('person').innerHTML = person.personScript();
document.getElementById('myBmi').innerHTML = person.myBmiCalc();
</script>
</center>
</body>