JavaScript Node.js Basics Create a Command Line Weather Application Retrieving Data - Solution

Luis Giraldo
Luis Giraldo
Full Stack JavaScript Techdegree Student 23,656 Points

parseInt will omit 0 at the beginning of a zip code

This is related to openweather API solution on the teacher's notes Hi guys, I just wanted to let you know, that if your query has a zip code for example 01581,

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

    const url = `${querystring.stringify(parameters)}`;

The parseInt will ignore the zero and will return 1581, being an invalid zip code in United States, (I think it has to be 5 digits), so, the url will have : ?zip=1581%2cus instead of ?zip=01581%2cus The API response will be statusCode 404 So make sure to validate that you have a 5 digits zip code before adding it to the url.

1 Answer

Zimri Leijen
Zimri Leijen
11,572 Points

Rather than converting it to an int, it's easier to just check it with regex.