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

ohboy
ohboy
2,232 Points

Don't understand what this is doing or why it's needed

const weather = require('./weather')

const query = process.argv.slice(2).join('').replace(' ', ''); const query2 = process.argv.slice(2);

weather.getData(query2) weather.getData(query);

//console logs Current temperature in Minneapolis is 40.1F Current temperature in Minneapolis is 40.1F

So I tried logging out both and they gave me the same output. What I don't understand is why .join and .replace is needed. What is it changing?

1 Answer

Steven Parker
Steven Parker
230,024 Points

The "replace" function is there to remove any spaces from the argument. If the argument you provide has no spaces, then it doesn't change anything. But it's there to handle any cases where a space is present in the argument.

ohboy
ohboy
2,232 Points

Holy cow that was fast. Thank you Steven Parker :D