所以,这是我的 jsfiddle:
https://jsfiddle.net/therealnemis/dxrdo9km/87/
正如你在heron()中看到的,我有三行代码,第三行是更改其中包含“answer”的标签,即我的HTML中的h3标签。如果我将标签放在第二行,那么当我按下标有“Something”的按钮时,代码将执行:
var answer = squareRoot(15);
//If the answer is NaN, this is due to the fact that the triangle is not possible.
document.getElementById("answer").innerHTML = squareRoot(15);
result = checkIfRealTriangle(answer);
当我按下标有 Something 的按钮时,这会起作用,因为 document.GetElementById 位于 checkIfRealTriangle 之前,其中包含 isNaN 函数。如果我将 getelementbyID 移至 isNaN 函数下方,那么当我按下标记为 Something 的按钮时,什么也不会发生。如果我摆脱 isNaN,一切都会正常。
最佳答案
您需要定义 checkIfRealTriangle(answer)
函数中的“区域”变量。如果您查看控制台,您会看到错误。
关于javascript - isNan 函数使下一行代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49782109/