Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) AJAX and APIs Call the jQuery $.getJSON method

Eric Biz
Eric Biz
4,916 Points

Weather API

I have completed all the tasks of this weather challenge but when I launch the browser the temperature is not displayed. Did I miss anything? I have also include the jquery CDN link in the html page. It just says: Current temperature:

2 Answers

Eric Biz
Eric Biz
4,916 Points

Here is my code: JQUERY


$(document).ready(function() { var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather'; var data = { q : "Portland,OR", units : "metric" }; function showWeather(weatherReport){ $('#temperature').text(weatherReport.main.temp); } function showWeather(weatherReport){ $('#temperature').text(weatherReport.main.temp); } $.getJSON(weatherAPI,data,showWeather); });

HTML


<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>What's the Weather Like?</title> <script src="http://code.jquery.com/jquery-1.12.4.min.js"</script> <script src="weather.js"></script> </head> <body> <button type="button" id=btn382>Click Me!</button> <div id="main"> <h1>Current temperature: <span id="temperature"></span>Ā°</h1> </div> </body> </html>