它给了我一个错误,尽管我将切片从数字转换为字符串,但切片不是函数. 问题在哪里?
var weight = prompt("Enter your Weight");
var height = prompt("Enter your Height");
function bmi(weight, height) {
var result = weight / Math.pow(height, 2);
var count = result.toString.slice(0, 4);
if (result < 18.5) {
alert("Your result is " + count + ", so you are underweight.");
} else if (result >= 18.5 && result <= 24.9) {
alert("Your result is " + count + ", so you have a normal weight.");
} else {
alert("Your result is " + count + ", so you are overweight.");
}
}
bmi(weight, height);
我将切片从数字转换为字符串,但给出了相同的错误,问题出在哪里?