See the Weather Anywhere


API's rule the world!
API=Application Programming Interface, a "door" some platforms leave open so you can get data from them. APIs let you take advantage of super powerful platforms, like openWeather, Google and Instagram, to add cool features to your projects, usually for free.

In this project we will work with our first API to show weather data.

Here is an example of a finished version


Directions
  1. Create at HTML page with an input field (city), a button and a label. Test to make sure it works: when you type something into the field and press the button, have it appear on the label.

  2. Set up your own account on openweathermap.org. Get an API key and save it as a variable in your code.

  3. Look up the documentation on https://openweathermap.org/current to get the syntax for a weather call using a city name. Make sure to add your APPID to the call. Create a request string using the City Name input and show it on the page

  4. Look up and understand JavaScript's XMLHttpRequest() method.

  5. Setup an XMLHttpRequest object (call it myXHR or similar). Add an eventListner to it. The event listener has a function that will do all the work of parsing the reply. It looks something like:

    myXHR.addEventListener("readystatechange", function()  {
    
         WORK HAPPENS HERE
     
    }, true);
    

    And don't forget to open and send your request.

  6. In the eventListener work function, get a response object and display the JSON on the page. Hint: use JSON.parse(myXHR.responseText)

  7. Now that you see the JSON, pull the elements you want out of the response and display them on the page.

  8. EXTRA CREDIT - look at the conditions for your selected city, and change the page background to an image showing the weather there.

  9. Finish the project till it looks perfect to you.

Have fun and good luck!


(c) 2017 by Code Craft Academy