JavaScript意外标识符错误代码

时间:2018-09-20 16:34:21

标签: javascript error-handling

我无法使此代码正确运行。它说我在以“ 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>

0 个答案:

没有答案