【发布时间】:2015-04-16 10:03:58
【问题描述】:
我是一名新的 Javascript 编码员,这是我在这里的第一个问题。
我有以下代码:
- 从名为 celsius 的变量中获取每个值
- 将该值传递给名为 calculate 的函数并将其转换为 华氏度。
- 华氏度的值取回第一个 函数,然后打印到第一个函数
function calculate() {
var celsius = [12, 45, 99, -40];
for (i=0 ; i<celsius.length; i++) {
document.write("The value is " + celsius[i] + " and is equal to " + count(celsius[i]) + "<br>")
}
}
function count(num) {
var degfarhen = 9/5 * parseFloat(num) + 32;
degfarhen = degfarhen.toFixed(1);
document.write(degfarhen)
}
但是会发生这种情况
53.6The value is 12 and is equal to undefined
113.0The value is 45 and is equal to undefined
210.2The value is 99 and is equal to undefined
-40.0The value is -40 and is equal to undefined
华氏度的值在句子之前打印,实际必须打印的位置未定义。
【问题讨论】:
标签: javascript html function for-loop undefined