【发布时间】:2016-01-27 22:27:49
【问题描述】:
我想要反馈为什么当附加到用户输入 var usergb 时 toFixed 在我的 JS 警报中不起作用。是一件很奇怪的事情。有人鼓励我发帖,但我在这里没有看到任何其他关于用户输入变量的 toFixed 问题的问题。
var downloadspeed = function () {
var usergb = prompt("How many gigabytes do you wish to download at 56 kilobits per second?");
console.log(usergb);
var hours = (usergb*8388608)/201600;
console.log(hours);
var days = (usergb*8388608)/4838400;
console.log(days);
//below in the alert is where you will see it, after the first concatenated string, I'd like to type usergb.toFixed(2) but it won't take.
alert("The number of hours it will take to download a " + usergb + " GB file at 56 kilobits per second is " + hours.toFixed(2) + " hours. This might be a big number. So, in terms of days to download, it'll take " + days.toFixed(2) + " days to download. This is why we have faster broadband speeds nowadays and why we have video streaming.");
}
downloadspeed();
我得到的错误是它不是一个函数。
格雷西,卢
【问题讨论】:
-
我刚刚在我的浏览器中运行了那个确切的代码,它工作正常。
-
@MikeC - 我认为,通过阅读代码中的注释,问题在于在警报中将
toFixed(2)添加到usergb -
@JaromandaX 你是对的。我错过了。
标签: javascript jquery methods