Unit 6, Lesson 12 - Random Forecast help

I’ve been teaching this for a few years, but traversals still cause me problems. I’m trying to build the random forecaster before students get here, and I thought I was on the right path, but I cannot get my filtered list to fill. I went back and looked at the teacher example, and I even asked Gemini, and it said it looks good.

Please help me out. What am I missing?

// Build the Random Forecaster app
var cityList = [(getColumn("Daily Weather", "City"))];
var forecastNumberList = [(getColumn("Daily Weather", "Forecast Number"))];
var filteredCityList = [];
var tomorrowsWeather = "2";
filter();
function filter() {
  for (var i = 0; i < 600; i++) {
    if (forecastNumberList[i] == tomorrowsWeather) {
      appendItem(filteredCityList, cityList[i]);
    }
  }
  console.log(filteredCityList);
}

When you create your list and intialize with getColumn, don’t put brackets around your getColumn. My students do that frequently so I recognize the error.

The getColumn brings in the brackets. If you put brackets around it, it makes a multi-dimensional array.

1 Like

Lightbulb!

Thank you! I created the lists using blocks and for getColumn you can just use the var block. As soon as you said that, I remembered some of my students had that problem later in the year last year, and they finally figured it out after a lot of hunting. I wouldn’t have remembered that, so thank you!