Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>Weather App</title>
</head>
<body>
<h1>Hola Mundo</h1>
<h1>Weather App</h1>
<p id="location"></p>
<script src="weather.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions weather.js
Original file line number Diff line number Diff line change
@@ -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();