Here's an exciting challenge: You'll be building a small weather app, using your newfound skills with APIs!
For this homework you'll be using your newfound knowledge of Ajax to create a weather app with the Open Weather API!!! This API requires you to sign up to get an API key (this way they can limit how many calls you make to their database). Here are the steps to get a key:
- Sign up for a free Open Weather Map account!
- Once you've signed up, you're given an API key. Copy that API key and keep track of it somewhere!
- Open Postman to check out the data you're working with & to verify that your key works. Make a GET requrest to the following URL in postman, adding your API key to the end.
http://api.openweathermap.org/data/2.5/weather?q=[ZIP CODE GOES HERE],us?units=imperial&appid=[PUT YOUR API KEY HERE]
- Complete the event listener
- When the submit button is clicked, get value of the input.
- Then invoke the
makeCall()
function with the zip code as an argument.
- Fill in the
makeCall()
function- Look at the Open Weather API Documentation
- This function has the zip code as a parameter.
- It will construct the url you will use for your Ajax call.
HINT:
The url will look something like: http://api.openweathermap.org/data/2.5/weather?q=[ZIP CODE GOES HERE],us?units=imperial&appid=[PUT YOUR API KEY HERE]
- Then it will preform an AJAX GET request and invoke
getData()
with the response data.
- Finish the
getData()
function- This function will take the response data and grab the following:
- City name
- Current temperature
- Weather description
- Min temp
- Max temp
- It will then pass these as arguments when invoking the
appendToDom()
function.
- This function will take the response data and grab the following:
- Complete the
appendToDom()
function- This function will take each of these parameters and create appropriate elements for each.
- It will then append the elements to the DOM.
Here are some zip codes to test!
- 99501 (Anchorage)
- 99723 (Barrow, AK)
- 60605 (Chicago)
- 70124 (New Orleans)
- 77030 (Houston, TX)
- 00902 (San Juan, Puerto Rico)
- 46923 (Delphi, IN)
- 94123 (San Francisco, CA)
- Add the latitude and longitude, humidity, precipitation, and wind speed
- Style your app more! Make it look pretty! Some advanced styling ideas:
- Have the temperature turn blue if under 40, and red if above 90.
- Look into the javascript date object and change the background color based on the time of day.
- Look into Font Awesome and add icons based on the weather.
Homework is due by 11:00 Sunday! Remember to work with each other and go to TAs when you need it, but follow the guidelines for queuing. Follow the rules for homework submission for creating your pull request to submit the homework.