0

所以我设置了一些简单的数学来为 madlibs 游戏添加一点天赋。然而每次我运行这个我得到一个十进制的答案而不是一个整数, Math.round(x, n) 也不起作用。是否有一些不正确的语法或我遗漏的东西?

let height = prompt("About how tall are you like inch-wise? 48 = 4 feet, 60 = 5 feet , 72 = 6 feet."); //for height multiple in story

if (isNaN(height)) {
    height = 66;
}
else {
    height = height;
};

height = height / 12;
console.log(height);
Math.round(height);
console.log(height); 
4

1 回答 1

4

JavaScript 不通过引用传递变量并Math.round返回四舍五入的值。所以你必须分配结果值。

height = Math.round(height);
于 2018-02-11T14:56:06.683 回答