Random Weather App won't work

This code should get the weather for a random city, but it doesn’t work (gives error/does not fill filter list). I cannot find the mistake, and several of my students are in the same predicament.

Hello @braffa,

The error is in your initialization of the variables on lines 3-8. When you call getColumn(), the value that is returned is a list. In your implementation you are calling this function within a list:
var forecastList = [(getColumn(“Daily Weather”, “Forecast Number”))];

because the return value is already a list, you’re actually creating a list inside of a list (sometimes called a 2D list). So if you look at the length of forecastList for example, you’ll find that it has a length of 1. That 1 thing in the list is another list of length 600. In filter() you compare that whole list of 600 items (integers) to the number 1, and it does not match, so nothing is put in to your filtered lists. When you get to updateScreen, the lists are empty which is giving you the error you’re seeing about an undefined value.

All you’ve got to do to solve the problem is fix these initializations by removing the brackets around the call to getColumn!

Hope that helps!
Madeline

1 Like

Oh wow, I can’t believe I didn’t notice that, thank you so much!!

1 Like