Skip to content

Instantly share code, notes, and snippets.

@bdfinlayson
Created January 29, 2015 19:11
Show Gist options
  • Save bdfinlayson/1916c1b3f5bcdfad95f8 to your computer and use it in GitHub Desktop.
Save bdfinlayson/1916c1b3f5bcdfad95f8 to your computer and use it in GitHub Desktop.

Revisions

  1. bdfinlayson created this gist Jan 29, 2015.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    'use strict';

    var userZipCode,
    startingUrl,
    customUrl;

    document.querySelector('#submitButton').addEventListener('click', function() {
    userZipCode = document.querySelector('#userZipCode').value;
    startingUrl = 'https://api.wunderground.com/api/152eccaad753eb4b/forecast10day/q/37207.json';
    customUrl = startingUrl.replace('37207', userZipCode);

    console.log("The user's zip code is: " + userZipCode);
    console.log("The starting url was: " + startingUrl);
    console.log("The weather json file link should be: " + customUrl);

    });

    function getJSON(customUrl, cb){
    var request = new XMLHttpRequest();
    request.open('GET', customUrl);

    request.onload = function () {
    if (this.status >= 200 && this.status < 400) {
    cb(JSON.parse(this.response));
    }
    }

    request.send();
    }