diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..57f5934 Binary files /dev/null and b/.DS_Store differ diff --git a/index.html b/index.html index 3233671..abc3a20 100644 --- a/index.html +++ b/index.html @@ -3,9 +3,11 @@ - Document + Weather App -

Hola Mundo

+

Weather App

+

+ \ No newline at end of file diff --git a/weather.js b/weather.js new file mode 100644 index 0000000..06901fa --- /dev/null +++ b/weather.js @@ -0,0 +1,19 @@ +// step 1 - create response object +let zipCode = new XMLHttpRequest(); +let zip = prompt("enter zipcode to get city & state"); + + +// step 2 - create call back + zipCode.onreadystatechange = function() { + if (zipCode.readyState === 4 && zipCode.status === 200) { + let response = JSON.parse(zipCode.responseText); + console.log(response); + let city = response.places[0]["place name"]; + let state = response.places[0]["state abbreviation"]; + document.getElementById('location').innerHTML = city + ", " + state; + } + } +// step 3 - create an open request + zipCode.open('GET', `http://api.zippopotam.us/US/${zip}`); +// step 4 - send the request + zipCode.send(); \ No newline at end of file