<commit_before>function getGeoLocation() {
  var output = document.getElementById('start');

  if (!navigator.geoloction) {
    output.innerHTML = 'Your browser does not support geolocation';
  }

  function success(position) {
    // cache lat and long coords
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    // IIFE that references coordinates for API call
    ( function getLocalWeather() {
      var URL = 'http://api.openweathermap.org/data/2.5/weather?lat=%lat%&lon=%long%&APPID=21f42111c89049ac9a71560c5fe1d747';
          URL = URL.replace('%lat%', latitude);
          URL = URL.replace('%long%', longitude);

      // TODO: ajax request for api JSON
    
    } )();

  }

  function error() {
    output.style['background-color'] = '#f75e5e';
    output.innerHTML = 'Unable to determine your location';

  }

  output.innerHTML = 'Tracking...';
  navigator.geolocation.getCurrentPosition(success, error);
}


// event handlers
document.getElementById('start').addEventListener('click', getGeoLocation);
<commit_msg>added makeRequest and alertContents functions for ajax call<commit_after>function getGeoLocation() {
  var output = document.getElementById('start');

  if (!navigator.geolocation) {
    output.innerHTML = 'Your browser does not support geolocation';
  }

  function success(position) {
    // cache coordinates
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;

    // IIFE that references coordinates for API call
    (function getLocalWeather() {
      var httpRequest;

      // openweathermap API settings
      var URL = 'http://api.openweathermap.org/data/2.5/weather?lat=%lat%&lon=%long%&APPID={APIKEY}';
      var API_KEY = '21f42111c89049ac9a71560c5fe1d747';

      URL = URL.replace('{APIKEY}', API_KEY);
      URL = URL.replace('%lat%', latitude);
      URL = URL.replace('%long%', longitude);

      // API request
      (function makeRequest() {
        httpRequest = new XMLHttpRequest();

        if (!httpRequest) {
          alert('Cannot create XMLHTTP instance');
          return false;
        }

        httpRequest.onload = alertContents;
        httpRequest.open('GET', URL);
        httpRequest.send();
      })();

      function alertContents() {
        if (httpRequest.readyState === XMLHttpRequest.DONE) {
          if (httpRequest.status === 200) {
            alert(httpRequest.responseText);
          } else {
            alert('There was a problem with the request.');
            console.log('Error: ', httpRequest.status);
          }
        }
      }

    })();

  }

  function error() {
    output.style['background-color'] = '#f75e5e';
    output.innerHTML = 'Unable to determine your location';

  }

  output.innerHTML = 'Tracking...';
  navigator.geolocation.getCurrentPosition(success, error);
}


// event handlers
document.getElementById('start').addEventListener('click', getGeoLocation);

{'fraction_non_alphanumeric': 0.13062605752961082, 'fraction_numerical': 0.01996615905245347, 'mean_word_length': 3.016304347826087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4454068', 'n_tokens_mistral': 910, 'n_tokens_neox': 842, 'n_words': 186}