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 Create a callback function

Matthew Clark
Matthew Clark
7,255 Points

What's happening here?

Please see code!

geoffrey
geoffrey
28,736 Points

Add your code please, there is nothing to see at the moment...

Matthew Clark
Matthew Clark
7,255 Points

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

Here is my code. I don't know what to do next.

1 Answer

The finally step of the challenge is asking you to insert the correct temperature into the div.

The jquery line: $("#temperature") has selected anything with the id temperature, in this case it is a span element, inside a h1 element, inside the div element the challenge is referring to.

In order to add text inside a html element with Jquery you use the text() method which allows for you to pass a String argument as a parameter.

Since you have successfully referenced the correct element to add the temperature text to the challenge then explain to you about the properties Open Weather Map API can return. (it returns a main property which has a temp property.) This being exactly what you need to add to the text.

All you must do is then use dot notation after the element with the id temperature you selected $("#temperature") to use the text method Jquery has provided.

Dot notation simply means to add literally a . after the selected object and then the method you wish to use on it. in this case .text()

After successfully adding the notation simple pass in weatherReport.main.temp to the method text as its parameters and success!

A parameter is what is inside the parenthesis

Didn't want to just give you the answer but I hope this explained it enough for you to solve the challenge and understand most of what is going on!

More about text() , Jquery() also know as $() , Dot notation

If you need more help feel free to ask! I will try to explain as best as I can, and there are many more treehouse members that will be able to explain just as much if not more!

Excellent work, enjoy the studies!