-2
If/else 성명으로 작업하고 있습니다. switch 문으로 변환하려고하는데 문제가 있습니다. 콘솔을 실행할 때 콘솔에 오류가없는 것 같습니다. 내가 입력 전류 위도와 경도를 할 수 있어야 내가 위도와 경도과에 가고 싶은 곳 출력이이 스위치 문에는 무엇이 잘못 되었습니까?
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;
}
}
그런데 한 가지 문제는 "위도"철자 것입니다 도움이 변수를 선언 할 때'Latitude'로, 그리고 몇 라인 후에 그것을 사용할 때'latitdue'로 나타납니다. – Pointy
왜 console.log()가 아니며 문제가있는 곳을 확인하십시오. 또는 예제 입력과 예상 출력을 제공합니까? –
'if' /'else' 캐스케이드를 사용해야합니다. 이 'switch'문보다 읽기 쉽고, 짧고, 단순하며, 에러가 발생하기 쉽습니다. – Bergi