Wanderlust Project - Error

Hi, I’m working on the wanderlust project in Learn JavaScript. When I enter a city, the top attractions show up, but the weather does not. Could someone help me understand this error?

[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating ‘currentDay.main’)
createWeatherHTML (helpers.js:13:106)
renderForecast (main.js:66)
(anonymous function) (main.js:76)
promiseReactionJob

Typically undefined errors are that you are trying to invoke some sort of function or method with a variable that’s undefined.

The trick is to find where this line is (it tells you) and trace where exactly it can become undefined. The potential reasons are many. Sometimes the code could be correct but the data needs to be loaded and so it needs some sort of asynchronous idea.

Your best bet is to track what object is undefined and test it interactively in the console.

Hmm, the error tells me the problem is in helpers.js line 13, evaluating currentDay.main. Helpers.js came with the project so I’m not sure why there would be an issue with it. The next line of the error message points to main.js 65. Here are code bytes for each:

helpers.js

const createWeatherHTML = (currentDay) => { console.log(currentDay) return `<h2>${weekDays[(new Date()).getDay()]}</h2> <h2>Temperature: ${kelvinToFahrenheit(currentDay.main.temp)}&deg;F</h2> <h2>Condition: ${currentDay.weather[0].description}</h2> <img src="https://openweathermap.org/img/wn/${currentDay.weather[0].icon}@2x.png">`; }

main.js

const renderForecast = (day) => { let weatherContent = createWeatherHTML(day); $weatherDiv.append(weatherContent); }

I had a problem with that project as well. I fixed it by resetting the project code. Some codes which came default with the project were wrong written, and when I reset it, different code showed up and I just did the project again and no errors showed up. Good luck and hope it helps!

Thanks! I reset the project code and tried in Chrome instead of Safari. It worked for me.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.