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 trialS Ananda
9,474 PointsStuck on quiz in Ajax basics
My last line of code is wrong. Everything worked up until then. Below are the instructions, the error code and my answer. I obviously missed something on how to use the .text() even after reading up on in in jquery.api.
Instructions: Finally, to insert the temperature into the div, use jQuery's text() method. You'll need to pass the temperature into this method. The Open Weather Map API returns an object with the property main; that property holds another object with the property "temp". To access the temperature, use dot syntax, like this: weatherReport.main.temp
Error message: Bummer! You need to chain the text() method to your selection. Add a dot after the jQuery selection, followed by 'text()'.
My code.
$(document).ready(function() { var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather'; var data = { q : "Portland,OR", units : "metric" }; function showWeather(weatherReport){ $("#temperature").html(statusHTML); $(‘#main”).text(); }; });
$(document).ready(function() {
var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather';
var data = {
q : "Portland,OR",
units : "metric"
};
function showWeather(weatherReport){
$("#temperature").html(statusHTML);
$('#main').text();
};
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>What's the Weather Like?</title>
<script src="jquery.js"></script>
<script src="weather.js"></script>
</head>
<body>
<div id="main">
<h1>Current temperature: <span id="temperature"></span>°</h1>
</div>
</body>
</html>
1 Answer
Joe Beltramo
Courses Plus Student 22,191 PointsYou are close.
The object that is returned into the showWeather
method as weatherReport
has a property called main
on it. In order to access this property temp
, you need to to use dot notation as shown in the instructions: weatherReport.main.temp
.
Then instead of using the jQuery method .html
, it is wanting you to use the .text
method.
So you have gotten this far:
function showWeather(weatherReport){
$("#temperature").html(statusHTML);
};
Try replacing the html
method with text
:
$("#temperature").text(statusHTML);
And then try replacing statusHTML
with weatherReport.main.temp
S Ananda
9,474 PointsS Ananda
9,474 PointsThanks Joe, that fixed the problem. Sometimes I'm still having problems knowing what to plug in where , but it is getting easier.
Joe Beltramo
Courses Plus Student 22,191 PointsJoe Beltramo
Courses Plus Student 22,191 PointsNever stop practicing, things get easier :]
S Ananda
9,474 PointsS Ananda
9,474 PointsI've been at JS for awhile now. Just recently things are starting to make sense, not all things obviously, but a lot more of them. Hoping to get some practical experience with JS tomorrow at a hackathon. That's why I'm trying to finish this module. They want me to do some programming with JSON. Lucky for me these folks are very patient and helpful. It's with a Code for America brigade, so they are trying to come up with tasks at different levels of experience. Really a great group.
Thanks again. Now I just have to get through the last challenge...
Joe Beltramo
Courses Plus Student 22,191 PointsJoe Beltramo
Courses Plus Student 22,191 PointsWell best of luck to you at your Hackathon. Most developers want you to success so it's not completely surprising they are patient and helpful. You can get through the last challenge. Just pay attention to the videos and what you are asked to do. Don't forget to play 'offline' (in your own environment) with the things you learn!
S Ananda
9,474 PointsS Ananda
9,474 PointsThanks for the encouragement Joe. I will pay close attention and I am playing some offline. Will do more shortly, as I'm trying to crank through a few tutorials. Once done with that I'll be doing a lot of playing, as I have a membership site I want to build.