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

Petar Karagenov
Petar Karagenov
8,608 Points

The readableQuery const

The url Andrew Chalkley uses does not do what is shown on the video. The url given in the documentation looks like this: http://api.wunderground.com/api/${key}/conditions/q/CA/San_Francisco.json - it includes a state. So now the get function requires one more property and also gives the part //const query = process.argv.slice(2).join("").replace(' ', '');// a serious issue. I am stuck with that.

Hi Petar , I had the same problem and fixed it by using:

var state = process.argv.slice(2)[0];
var city = process.argv.slice(3);

var queryString = `https://api.wunderground.com/api/${api.key}/conditions/q/${state}/${city}.json`

and giving the function the two arguments:

weather.get(state,city);

I admit it is not very elegant, maybe someone found a prettier solution ?

nico dev
nico dev
20,364 Points

Great answer!

If I could, I'd vote it best answer definitely!

1 Answer

With destructuring assignment, you can also do this:

const [,, state, city] = process.argv;

var queryString = `https://api.wunderground.com/api/${api.key}/conditions/q/${state}/${city}.json`;