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 Retrieving Data - Solution

Trevor Maltbie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Trevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 Points

Two word cities don't work

If I type "node app San Jose, CA" or "node app San Jose" it never works since the city is two words.

I'm confused how to exactly make this work?

4 Answers

Gergely Bocz
Gergely Bocz
14,244 Points

Hi Trevor!

As far as i know, there is no way multiple word long file names work, as everything after the first one will be automatically treated an argument. Therefore, the only natural way is to format the filename according to a specific case. The most common suggestion i found is kebab-case, though i got used to snake-case a while back and i think it should work fine. Here is a stackoverflow question about naming conventions. That's all i can help you with, hope it's enough.

Gergely Bocz
Gergely Bocz
14,244 Points

Sorry i just realized your question was about multiple word long arguments, and not file names. It's pretty much the same case as file names: You have to compress a multiple word argument into a 1 word argument. Now when retrieveing data from a DB or through an API, you should use their convention. So in this case if api.wunderground's data can be accesed like San_Jose then use that, if it's San-Jose, use that, so on. Unfortunately their services are down atm, so i cannot check their format.

Heya! I saw that Gergely gave a good response, but I wanted to follow up with one of solving this. What I did was use regex to find all underscores and replace it with a space. It is currently functioning for me. Let me know if you have any questions. :)

        const zipCode = parseInt(query);
        if(!isNaN(zipCode)) {
            parameters.zip = zipCode + ',us';
        } else {
            parameters.q = query.replace(/_/g, '  ') + ',us'
        } 

I thought that issue was already solved in the app.js file const query = process.argv.slice(2).join(" ");