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

Blake Baxendell
Blake Baxendell
16,344 Points

Is anyone else getting the wrong location name?

Here is my code

const https = require('https');
const api = require('./api.json');

//Print Out Temp Details
function printWeather(weather) {
    const message = `Current temperature in ${weather.location.city} is 
    ${weather.current_observation.temp_f}F`;
    console.log(message);
}
//Print out error message

function get(query) {
    const request = https.get(`https://api.wunderground.com/api/${api.key}/geolookup/conditions/q/${query}.json`,
        response => {
            let body = "";
            //Read data
            response.on('data', chunk => {
                body += chunk;
            });
            response.on('end', ()=> {
                //Parse data
                const weather = JSON.parse(body);
                //Print data
                printWeather(weather);
            });
    });
}

module.exports.get = get;

It seems to be working for the most part besides that the location names seem to be wrong. Maybe that could be an issue with the API itself, but when I type in the same zip on the Wunderground website it pops up the right location. Also when I try 90210 like in the video I get an error.

TypeError: Cannot read property 'city' of undefined