I am trying to make a time conversion tool, first thing it does is gets the co-ordinates of both the cities you enter and then calculates time accordingly.
But the problem I am facing is that the function which gets the co-ordinates takes some time and it is asynchronous as well and thus there are issues with the execution order.
Is there are a way I can make sure that execution of a next statement gets done one after the previous completes?
function initializeConversion() { //Gets the date from non hidden fields and converts it to the format which is required if (document.getElementById('datenh1').value.length == 0) //Finds the non-empty field setValueOfDateTwo(); else setValueOfDateOne(); //Get the value from the fields cityOneString = document.getElementById('city1').value; cityTwoString = document.getElementById('city2').value; //Logging Statements console.log("City 1: "+cityOneString); console.log("City 2: "+cityTwoString); //Gets the coordinates of both cities //This is where the issue is getCoordinates(cityOneString); getCoordinates(cityTwoString); } You can check the whole code here on github: https://github.com/udit96rc/TimeConverter
You can check the tool here: http://uditchugh.me/pt
Promisea try.