[英]How to assign a prompt value to function parameter
So i have this code:所以我有这个代码:
<div class="wrapper">
<p id="ex"></p>
<script>
function celMessager() {
var celMs = window.prompt("Enter the celsius grades:");
celMs = parseFloat(celMs);
if (celMs == null) {
document.getElementById("ex").innerHTML = "Error.";
}
else {
document.getElementById("ex").innerHTML = celConversor();
}
}
</script>
<button class="button" type="button" onclick="
celMessager();
">
Conversor Celsius.
</button>
</div>
And i want to store the value of the user input (celMs) into the only parameter that celConversor() takes:我想将用户输入(celMs)的值存储到 celConversor() 采用的唯一参数中:
function celConversor(celGrades) {
fahGrades = (celGrades * 9/5) + 32;
return fahGrades;
}
So the number that the user enters, become the celsius grades that are going to change into fahrenheit and show it as a paragraph.所以用户输入的数字,就变成了摄氏等级,会变成华氏度,并显示为一个段落。 How can I do this?我怎样才能做到这一点? tried making the celGrades variable = to celMs and celMs to celGrades, but it always returns "NaN" in the paragraph, even after i added the "parseFloat" line.尝试将 celGrades 变量 = 设置为 celMs 并将 celMs 设置为 celGrades,但它始终在段落中返回“NaN”,即使在我添加了“parseFloat”行之后也是如此。
You're getting this error celConversor
requires a parameter, but you're not passing any parameters to it.您收到此错误celConversor
需要一个参数,但您没有将任何参数传递给它。 Change this line:更改此行:
document.getElementById("ex").innerHTML = celConversor();
to this:对此:
document.getElementById("ex").innerHTML = celConversor(celMs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.