JavaScript Node.js Basics Create a Command Line Weather Application Parsing Data and Printing - Solution

Getting error. Please help

1 Answer

Steven Parker
Steven Parker
194,522 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:{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.