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 trialTrent Stenoien
Full Stack JavaScript Techdegree Graduate 21,632 PointsThere is no function
What's going on here? I keep writing and rewriting my function but it says it's not there. It should be the following, but the challenge won't pass me.
function showWeather(weatherReport) { };
$(document).ready(function() {
var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather';
var data = {
q : "Portland,OR",
units : "metric"
};
});
function showWeather(weatherReport) { };
<!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>
EDIT: Here's the error I get. " Bummer! There's no showWeather function. Check the name you used when creating the function. Here's one way to create a function: function functionName(parameter) { }"
EDIT2: Figured it out. I was putting my function outside of the document.ready condition. Whoops!
1 Answer
andren
28,558 PointsThe instructions are not at all clear on this, but the function is meant to be nested inside of the anonymous function that is being passed in to $(document).ready()
method like this:
$(document).ready(function() {
var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather';
var data = {
q : "Portland,OR",
units : "metric"
};
function showWeather(weatherReport) { };
});
The error states there is no function named showWeather
because it was only looking for the function within that anonymous function, not in the global scope where you actually defined the function.
Edit: Ops I see that my answer came a bit late, oh well, as long as you solved the issue that's all that matters.