Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript脚本赢得';t使用我的'执行;如果';声明_Javascript_If Statement - Fatal编程技术网

Javascript脚本赢得';t使用我的'执行;如果';声明

Javascript脚本赢得';t使用我的'执行;如果';声明,javascript,if-statement,Javascript,If Statement,我正在处理一项作业,我不明白为什么在我放入else if时脚本不会执行 以下是我目前脚本中的内容 //Declaring Variables var intCurrentLatitude = new Number(0); var intCurrentLongitude = new Number(0); var intDestinationLatitude = new Number(0); var intDestinationLongitude = n

我正在处理一项作业,我不明白为什么在我放入
else if
时脚本不会执行

以下是我目前脚本中的内容

//Declaring Variables

var intCurrentLatitude = new Number(0);         
var intCurrentLongitude = new Number(0);        
var intDestinationLatitude = new Number(0);     
var intDestinationLongitude = new Number(0);

//Prompting User to enter in values

intCurrentLatitude = prompt ("What is your current latitude in degrees? (-90 to 90)");
intCurrentLongitude = prompt ("What is your current longitude in degrees? (-180 to 180)");
intDestinationLatitude = prompt ("What is your destination's latitude in degrees? (-90 to 90)");
intDestinationLongitude = prompt ("What is your destination's longitude in degrees? (-180 to 180)");

//Else ifs

if (intCurrentLatitude <= intDestinationLatitude && intCurrentLongitude <= intDestinationLongitude)
{
    alert("Head North East");
}
else if (intCurrentLatitude <= intDestinationLatitude && intCurrentLongitude => intDestinationLongitude)
{
    alert("Head North West");
}
else
{
    alert("Land hoy!");
}
//声明变量
var intCurrentLatitude=新编号(0);
var intCurrentLongitude=新编号(0);
var intdestinationlatude=新编号(0);
var IntDestinationLongIntence=新编号(0);
//提示用户输入值
intCurrentLatitude=prompt(“您当前的纬度是多少度?(-90到90)”);
IntCurrent经度=提示符(“以度为单位的当前经度是多少?(-180到180)”;
intdestinationlatude=prompt(“目的地的纬度是多少度?(-90到90)”);
intdestinationlongitence=prompt(“目的地的经度是多少度?(-180到180)”);
//否则如果

else if语句中的if(intCurrentLatitude:

intCurrentLongitude => intDestinationLongitude
浏览器将=>解释为无效的赋值。任何大于/小于运算符都需要在等号之前。以下是正确的-

intCurrentLongitude >= intDestinationLongitude

您不必将变量初始化为
新编号(0)
。只需使用
var myvar=prompt('which')
。另外请注意
新编号(0)
返回一个对象,而不是一个数字。@RandomUser这不是本网站的工作方式。拒绝投票是内容,而不是用户。用户代表应该与我们是否应该拒绝投票或关闭投票无关。@Rion,作为将来的参考,您应该在编辑器、构建过程或手动中使用某种形式的javascript验证。jshint可能是最常见的,也可以在这里找到:许多编辑器现在都能够将jshint直接集成到编辑器中,以简化此过程。通过遵循验证器强制执行的标准,您的代码将不那么容易出错,并且更加一致。哇,我觉得自己太傻了。谢谢大家。我知道这是真的像这样愚蠢的事情。我就是看不出来。非常感谢。很好的发现。你比我快了几秒钟!谢谢你的编辑,Trlson。还有@Rion,下次检查开发人员控制台(通常是Ctrl-Shift-I或F12)。它会显示你代码中的大部分错误。可能是另一个愚蠢的问题,我对这个问题完全陌生(应该相当明显),我的导师从来没有告诉我们要使用哪种文本编辑器,我只是用记事本过日子。你建议我使用或研究哪一种?关于这个主题已经有很多帖子了。而且,评论应该集中在手头的问题上,所以打开新的问题或寻求进一步的建议。总之,记事本++,Sublime Text或TextWrangler是初学者的好选择。