我在 If / else 语句中使用它。我试图将其转换为switch语句,但我遇到了麻烦。我运行时似乎没有在控制台中出现任何错误。我应该能够输入当前的lat和lon以及我想要进入lat和lon的位置,输出应该是一个方向
function caseSwitch(intCurrentLatitude, intCurrentLongitude, intDestinationLatitude, intDestinationLongitude){
//var intCurrentLatitude = parseFloat(prompt("What is your current Latitude?"));
//var intCurrentLongitude = parseFloat(prompt("What is your current Longitude?"));
//var intDestinationLatitude = parseFloat(prompt("What is your destination Latitude?"));
//var intDestinationLongitude = parseFloat(prompt("What is your destination longitude?"));
var Latitude = intCurrentLatitude;
var longitude = intCurrentLongitude;
var latitude_end = intDestinationLatitude;
var longitude_end = intDestinationLongitude;
var output = document.getElementById("case/switchConstruct");
var end = intDestinationLatitude - latitdue;
var end2 = intDestinationLongitude - longitude;
switch (true){
case (end > 0 && end2 > 0) :
output.textContent = "We'd be headed North East, capt'n!";
break;
case(end > 0 && end2 < 0) :
output.textContent = "Ye'd best head North West, captain!";
break;
case(end < 0 && end2 > 0) :
output.textContent = "Ye'd best head South East, captain!";
break;
case(end < 0 && end2 < 0) :
output.textContent = "Ye'd best head South West, captain!";
break;
case(end === 0 && end2 === 0) :
output.textContent = "Ye'd best head some direction, captain!";
break;
case(end < 0 && end2 === 0) :
output.textContent = "Ye'd best head South, captain!";
break;
case(end > 0 && end2 === 0) :
output.textContent = "Ye'd best head North, captain!";
break;
case(end === 0 && end2 < 0) :
output.textContent = "Ye'd best head West, captain!";
break;
case(end === 0 && end2 > 0) :
output.textContent = "Ye'd best head East, captain!";
break;
default :
output.textContent = "Capt'n, give us better directions!?!";
break;
}
}
答案 0 :(得分:1)
一切正常,你只是拼写了Latitude错误......
更改
var end = intDestinationLatitude - latitdue;
要强>
var end = intDestinationLatitude - Latitude;
反之亦然...... javascript区分大小写......
在这里工作:
http://codepen.io/theConstructor/pen/OXVxbK?editors=1010
希望这有帮助