Coding Challenge – Airport Distance Calculation

Create the JavaScript web application which auto completes airport names for all international airports and calculates the distance between two airports once selected.

To Solve this problem first we need to create the UI which allows us to search Airport. Once we have UI we need to fetch the airport data and compares it with user input and display the suggestions.

Here is the HTML template which create Airport Search UI:

<!DOCTYPE html>

  <script src="autocomplete.js"></script>


  <div id="map"></div>
    Please Enter Origin Airport
  <div id="autocomplete-container">
    <p>Modify the text in the input field, then click outside the field to fire the onchange event.</p>

    Enter some text: <input type="text" name="txt" onchange="autoData(this.value)">

    <ul id="autocomplete-results"></ul>



Here is the Javascript to calculate Suggestions from the Airport Data:

const autoData = (val) => {
  function(response) {
    if (response.status !== 200) {
      console.log('Looks like there was a problem. Status Code: ' +

    // Examine the text in the response
    response.json().then(function(data) {
      let dataArr = autocomplete(val, data); => {
        const liTag = document.createElement('li');
.catch(function(err) {
  console.log('Fetch Error :-S', err);

const autocomplete = (val, data) => {
  var people_return = [];

  for (i = 0; i < data.length; i++) {
    let currAirport = data[i].code.toLowerCase();
    if (val === currAirport.slice(0, data.length)) {

  return people_return;

Here are the Airport JSON Data for the Airports:

      "name":"Lehigh Valley International Airport",
      "name":"Abilene Regional Airport",