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 Node.js Basics 2017 Create a Command Line Weather Application Parsing Data and Printing - Solution

Getting error. Please help

1 Answer

Steven Parker
Steven Parker
231,236 Points

First off, template strings must be enclosed in accents (`) instead of apostrophes (') for interpolation to be performed.

But in addition to that, if you try opening the URL directly with your browser, you will see that the API returns this response:

{"cod":"400","message":"Nothing to geocode"}

Clearly there is no "name", or "main.temp" in this response. But you can see this usage example on the API's information page:

API call:
api.openweathermap.org/data/2.5/weather?q={city name}   :point_left: note the "q="

If you look closely at your URL, you can see that there is no "q=" before the city name. Based on the comments, the function previously took a "city" argument and added that part to it, but it now takes a "query" argument and does not. So the call at the bottom of the script should probably be:

getWeather("q=New Jersey");  // note "q=" added

Optional suggestion: A nice enhancement might be to check the contents of "cod" in the API response to see if an error occurred, and if so display the contents of "message" to the user.