[英]Why am i getting this NaN?
I made a javascript with simple math but i keep getting NaN (Not a Number) as the output. 我用简单的数学程序制作了一个javascript,但我不断得到NaN(不是数字)作为输出。
This is the original equation https://upload.wikimedia.org/math/9/5/d/95d176cfd7d8ab9e4df1977f0926d1d0.png 这是原始方程式https://upload.wikimedia.org/math/9/5/d/95d176cfd7d8ab9e4df1977f0926d1d0.png
And here is my code: 这是我的代码:
<html>
<head>
<title></title>
<script>
function showheight() {
var chi = 23 * (Math.PI) / 180;
var vara = 6378137;
var varb = 6356752.31425;
var varR = (Math.sqrt(((Math.pow(((Math.pow(vara, 2)) * (Math.cos(chi))), 2)) + (Math.pow(((Math.pow(varb, 2)) * (Math.sin(chi)))))) / ((Math.pow((vara * (Math.cos(chi))), 2)) + (Math.pow((varb * (Math.sin(chi))), 2)))));
document.getElementById("radius").innerHTML = varR;
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(showheight);
</script>
</head>
<body>
<p id="radius"></p>
</body>
</html>
PS: I am a newbie. PS:我是新手。
The problem is here 问题在这里
var varR = (Math.sqrt(((Math.pow(((Math.pow(vara, 2)) * (Math.cos(chi))), 2)) + (Math.pow(((Math.pow(varb, 2)) * (Math.sin(chi)))))) / ((Math.pow((vara * (Math.cos(chi))), 2)) + (Math.pow((varb * (Math.sin(chi))), 2)))));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Math.pow(((Math.pow(varb, 2)) * (Math.sin(chi))))
only one parameter for that Math.pow 该Math.pow的仅一个参数
var varR = (Math.sqrt(((Math.pow(((Math.pow(vara, 2)) * (Math.cos(chi))), 2)) + (Math.pow(((Math.pow(varb, 2)) * (Math.sin(chi))), 2))) / ((Math.pow((vara * (Math.cos(chi))), 2)) + (Math.pow((varb * (Math.sin(chi))), 2)))));
gives 6374895.33901514 as an answer - is that what you expect? 给出6374895.33901514的答案-这是您期望的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.