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.
'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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment