Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,309 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.