# Unit 5 Lesson 12 Random Forecaster - Help

**URL:** <https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435>\
**Category:** Unit and Lesson Discussion\
**Created:** [November 17, 2021, 5:45pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435 "2021-11-17T17:45:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rossiai](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/rossiai/32/7776_2.png) [@rossiai](https://forum.code.org/u/rossiai)\
**Post date:** [November 17, 2021, 5:45pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/1 "2021-11-17T17:45:30Z")

</div>

I have two comments/questions about the code for this project. I would appreciate some feedback

1. Based on the instructions, the app should tell the weather **tomorrow** , but the Example solution uses forecastNumberList[i] == 1. This will actually pick up the weather for **today.**

2. I do not understand why the function in the Example solution is traversing the cityList and using a conditional for the forecastNumberList. I feel the conditional should be based on the same list.

In my own version I used a different approach. I do understand that there are several ways to accomplish the same, I just do not understand what the code in the example does.

I traversed the forecastNumberList. When doing so, if i == 2, then I append the items at the same index for each of the other lists. I traverse the forecastNumberList and my conditional refers to the forecastNumberList. Please see the example below.

This is the [link to my app.](https://studio.code.org/projects/applab/bpNcJ-x_R49VG2gaY39ycQcBTXngGBjrsFugdsOojFU)

**Example**  
function filter(){  
for(var i=0; i\<cityList.length; i++){  
if(forecastNumberList[i] == 1){  
appendItem(filteredCityList, cityList[i]);  
appendItem(filteredIconList, iconList[i]);  
appendItem(filteredHighTempList, highTempList[i]);  
appendItem(filteredLowTempList, lowTempList[i]);  
appendItem(filteredConditionDescriptionList, conditionDescriptionList[i]);  
}  
}  
}

**My own**  
function filter() {  
for (var i = 0; i \< forecastsNumbers.length; i++) {  
if (forecastsNumbers[i]==2) {  
appendItem(filteredCitiesNames, citiesNames[i]);  
appendItem(filteredConditions, conditions[i]);  
appendItem(filteredIcons, icons[i]);  
appendItem(filteredLowTemperatures, lowTemperatures[i]);  
appendItem(filteredHighTemperatures, highTemperatures[i]);  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [November 18, 2021, 2:53pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/2 "2021-11-18T14:53:24Z")

</div>

I noticed that 1 is today’s weather myself. If the database has not been updated in a day it is yesterday’s weather. Looking at the Date column to find out what number to use is probably too complex. Just use 2.

`cityList.length` is equal to `forecastsNumbers.length` because of the way `getColumn()` works. However, I would call that a bad example to show the kids. I prefer your example.

Personally, I would go a step further.

```auto
var Tomorrows_Weather = 2;

function filter() {
  for (var i = 0; i < forecastsNumbers.length; i++) {
    if (forecastsNumbers[i] == Tomorrows_Weather) {
      appendItem(filteredCitiesNames, citiesNames[i]);
      appendItem(filteredConditions, conditions[i]);
      appendItem(filteredIcons, icons[i]);
      appendItem(filteredLowTemperatures, lowTemperatures[i]);
      appendItem(filteredHighTemperatures, highTemperatures[i]);
    }
  }
}

```

The reason for including the constant is that I have seen the idiom `if(someArray[i] == 1){` in a bunch of posts with people asking what is going wrong. Since our kids look at this as a pattern they repeat it but they don’t understand what that `== 1` is doing and just copy it. Naming it might help.

---

<div class="post-metadata">

**Author:** ![rossiai](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/rossiai/32/7776_2.png) [@rossiai](https://forum.code.org/u/rossiai)\
**Post date:** [November 18, 2021, 2:57pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/3 "2021-11-18T14:57:28Z")

</div>

Thank you so much. I love your solution. I will share it with my students. I agree with you that the example is not the best.

Thank you for answering. 🙂🙂

---

<div class="post-metadata">

**Author:** ![ken](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/ken/32/6111_2.png) [@ken](https://forum.code.org/u/ken)\
**Post date:** [November 18, 2021, 3:48pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/4 "2021-11-18T15:48:23Z")

</div>

Thanks for bringing up this question. The usage of the `forecastNumber` column in the database seems to be a change from when this lesson was first written. I’ll update the example for this lesson! Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [November 18, 2021, 11:50pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/5 "2021-11-18T23:50:36Z")

</div>

You might also want to give the number a name as in the example. I have seen at least 5 posts with that exact mistake. I hadn’t realized until I saw this that is the source of the misunderstanding.

---

<div class="post-metadata">

**Author:** ![mpogue](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mpogue](https://forum.code.org/u/mpogue)\
**Post date:** [February 9, 2022, 6:46pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/6 "2022-02-09T18:46:25Z")

</div>

Ignore my bug submission. I submitted it before checking here and I see you mentioned you will change it. I kept wondering where my kids were getting 1 and why they were so insistent that something told them it had to be 1.

---

<div class="post-metadata">

**Author:** ![dzulkiewski](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/dzulkiewski/32/84_2.png) [@dzulkiewski](https://forum.code.org/u/dzulkiewski)\
**Post date:** [February 14, 2022, 5:45pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/7 "2022-02-14T17:45:22Z")

</div>

I am running into the uistring issue with a student as well. I have gone through the solution and can’t seem to figure out what the student did wrong. Here is the link:

> **[Check out what I made](https://studio.code.org/projects/applab/sEHyDU98q0yTKsop_1AXCkAOwj_eeBJD2QSbh5UBiDk)**
>
> I wrote the code myself with Code.org

[https://studio.code.org/projects/applab/sEHyDU98q0yTKsop\_1AXCkAOwj\_eeBJD2QSbh5UBiDk](https://studio.code.org/projects/applab/sEHyDU98q0yTKsop_1AXCkAOwj_eeBJD2QSbh5UBiDk)

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [February 14, 2022, 6:11pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/8 "2022-02-14T18:11:15Z")

</div>

Your lists are empty. You must remove the “[” and “]” where you are initializing your lists. For example, line 4 should be as shown below (without the square braces).

var forecastNumbers = (getColumn(“Daily Weather”, “Forecast Number”));

---

<div class="post-metadata">

**Author:** ![dzulkiewski](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/dzulkiewski/32/84_2.png) [@dzulkiewski](https://forum.code.org/u/dzulkiewski)\
**Post date:** [February 14, 2022, 6:27pm UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/9 "2022-02-14T18:27:32Z")

</div>

Thank you so much, I didn’t even notice the   
I appreciate the second set of eyes

---

<div class="post-metadata">

**Author:** ![claudetteguy16](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@claudetteguy16](https://forum.code.org/u/claudetteguy16)\
**Post date:** [April 7, 2022, 11:41am UTC](https://forum.code.org/t/unit-5-lesson-12-random-forecaster-help/35435/10 "2022-04-07T11:41:57Z")

</div>

I think someone mentioned this, but the daily weather dataset doesn’t seem to be updated in a timely manner. I have class in about 20 minutes, but the data set shows “today’s weather” (Forecast Number 1) as “Wed 4/6”. Today is 4/7. When does that data set get repoplulated? It would be great if it could be done overnight for those of us with early school start times. Thanks!
