javascript - Why does If Else statment not output anything? -
attempting have user input 4 numbers, are, , destination. have output direction heading.
no matter values enter same thing happens. how can make code use results of prompts?
var output = document.getelementbyid("output"); var number=prompt ("what current latitude?"); var number=prompt ("what current longitude?"); var number=prompt ("what destination latitude?"); var number=prompt ("what destination longitude?"); var intcurrentlatitude = 0; var intcurrentlongitude = 0; var intdestinationlatitude = 0; var intdestinationlongitude = 0; if ( (intcurrentlatitude<=intdestinationlatitude) && (intcurrentlongitude<=intdestinationlongitude) ) { output.textcontent = "we'd headed north east, capt'n!"; } else if ( ( intcurrentlatitude<=intdestinationlatitude) && (intcurrentlongitude>=intdestinationlongitude) ) { output.textcontent = "ye'd best head north west, captain!"; } else if ( ( intcurrentlatitude>=intdestinationlatitude) && (intcurrentlongitude>=intdestinationlongitude) ) { output.textcontent = "ye'd best head south west, captain!"; } else if ( ( intcurrentlatitude>=intdestinationlatitude) && (intcurrentlongitude<=intdestinationlongitude) ) { output.textcontent = "ye'd best head south east, captain!"; } else{ output.textcontent = "land ho!"; }
html
<head> <meta charset="utf-8"> <title>more if</title> <body> <div id= "output"> <div id= "input2"> </div> </body> <script src="moreif.js"></script> <script src="moreif2.js"></script> </head> </html>
you kept changing number value , prompt returns string. use parsefloat
convert decimal in string form number. did not use result of prompts.
var output = document.getelementbyid("output"); var intcurrentlatitude = parsefloat(prompt("what current latitude?")); var intcurrentlongitude = parsefloat(prompt("what current longitude?")); var intdestinationlatitude = parsefloat(prompt("what destination latitude?")); var intdestinationlongitude = parsefloat(prompt("what destination longitude?")); if ( (intcurrentlatitude<=intdestinationlatitude) && (intcurrentlongitude<=intdestinationlongitude) ) { output.textcontent = "we'd headed north east, capt'n!"; } else if ( ( intcurrentlatitude<=intdestinationlatitude) && (intcurrentlongitude>=intdestinationlongitude) ) { output.textcontent = "ye'd best head north west, captain!"; } else if ( ( intcurrentlatitude>=intdestinationlatitude) && (intcurrentlongitude>=intdestinationlongitude) ) { output.textcontent = "ye'd best head south west, captain!"; } else if ( ( intcurrentlatitude>=intdestinationlatitude) && (intcurrentlongitude<=intdestinationlongitude) ) { output.textcontent = "ye'd best head south east, captain!"; } else{ output.textcontent = "land ho!"; }
<head> <meta charset="utf-8"> <title>more if</title> <body> <div id= "output"> <div id= "input2"> </div> </body> <script src="moreif.js"></script> <script src="moreif2.js"></script> </head> </html>