Title: Code.org AppLabs: I am unable to get a specific whether condition on and display it on the screen
Tags: javascript;code.org
Question: I'm working on this weather app, but I ran into a problem where I am unable to get the specific whether condition from the data set onto the screen. It always displays the whether condition for one of the cities, but not the others. I need some help on this if possible, and could be a big help if you point out any mistakes I have made.


```//The variables
var low = getColumn("Daily Weather", "Low Temperature");
var high = getColumn("Daily Weather", "High Temperature");
var city = getColumn("Daily Weather", "City");
var icon = getColumn("Daily Weather", "Icon");
var condition = getColumn("Daily Weather", "Main Condition");
var forecastNum = getColumn("Daily Weather", "Forecast Number");
var id = 0;
//filtered variables
var todayLow = [];
var todayHigh = [];
var todayCondition = [];
var todayIcon = [];

onEvent("locationDropdown", "change", function( ) {
  if (getText("locationDropdown") == "Anchorage, Alaska") {
    id = 1;
  } else if ((getText("locationDropdown") == "Fairbanks, Alaska")) {
    id = 6;
  } else if ((getText("locationDropdown") == "Denver/Boulder, Colorado")) {
    id = 16;
  } else if ((getText("locationDropdown") == "Chicago, Illinois")) {
    id = 31;
  } else if ((getText("locationDropdown") == "Des Moines, Iowa")) {
    id = 56;
  } else if ((getText("locationDropdown") == "Goodland, Kansas")) {
    id = 66;
  } else if ((getText("locationDropdown") == "Louisville, Kentucky")) {
    id = 86;
  } else {
    id = 96;
  }
});

onEvent("conditionButton", "click", function( ) {
  updateScreen();
  setScreen("screen2");
});
onEvent("conditionButton1", "click", function( ) {
  updateScreen();
  setScreen("screen2");
});
onEvent("tempButton", "click", function( ) {
  updateScreen();
  setScreen("screen3");
});
onEvent("homeButton1", "click", function( ) {
  updateScreen();
  setScreen("screen1");
});
onEvent("homeButton2", "click", function( ) {
  updateScreen();
  setScreen("screen1");
});
onEvent("temperatureButton", "click", function( ) {
  updateScreen();
  setScreen("screen3");
});
function updateScreen() {
  var index = id;
  console.log(id);
  for (var i = 0; i < 8; i++) {
    if (forecastNum[i] == 1) {
      appendItem(todayLow, low[i]);
      appendItem(todayHigh, high[i]);
      appendItem(todayCondition, condition[i]);
      appendItem(todayIcon, icon[i]);
    }
  }
  setText("lowTemp", todayLow[1]);
  setText("highTemp", todayHigh[1]);
  setText("label2", todayCondition[1]);
  setProperty("image2", "image", todayIcon[1]);
  console.log(idNum);
  console.log(index);
  console.log(todayLow);
}```
```=```




Comment: Your code example doesn't work. 1. The html part only has a `=` 2. You probably forgot to load dependency scripts because the error in the console says: "ReferenceError: getColumn is not defined"


Here is another answer: ```function updateScreen() {
  var index = id;
  console.log(id);
  for (var i = 0; i < 8; i++) {
    if (forecastNum[i] == 1) {
      appendItem(todayLow, low[i]);
      appendItem(todayHigh, high[i]);
      appendItem(todayCondition, condition[i]);
      appendItem(todayIcon, icon[i]);
    }
  }
  setText(&quot;lowTemp&quot;, todayLow[1]);
  setText(&quot;highTemp&quot;, todayHigh[1]);
  setText(&quot;label2&quot;, todayCondition[1]);
  setProperty(&quot;image2&quot;, &quot;image&quot;, todayIcon[1]);
  console.log(idNum);
  console.log(index);
  console.log(todayLow);
}
```
Correct me if I'm wrong, but I believe this is where the problem is. Whenever you want to update the screen, it only updates it to whatever is index 1 inside ```todayLow``` ```todayHigh``` ```todayCondition```  and ```todayIcon``` arrays.  Instead of putting &quot;1&quot; for the array of these, you should find a way to automatically change the value based on whatever dropdown the user selected. Also, not really a bad thing that you did, but instead of doing:
```onEvent(&quot;locationDropdown&quot;, &quot;change&quot;, function( ) {
  if (getText(&quot;locationDropdown&quot;) == &quot;Anchorage, Alaska&quot;) {
    id = 1;
  } else if ((getText(&quot;locationDropdown&quot;) == &quot;Fairbanks, Alaska&quot;)) {
    id = 6;
  } else if ((getText(&quot;locationDropdown&quot;) == &quot;Denver/Boulder, Colorado&quot;)) {
    id = 16;
  } else if ((getText(&quot;locationDropdown&quot;) == &quot;Chicago, Illinois&quot;)) {
    id = 31;
  } else if ((getText(&quot;locationDropdown&quot;) == &quot;Des Moines, Iowa&quot;)) {
    id = 56;
  } else if ((getText(&quot;locationDropdown&quot;) == &quot;Goodland, Kansas&quot;)) {
    id = 66;
  } else if ((getText(&quot;locationDropdown&quot;) == &quot;Louisville, Kentucky&quot;)) {
    id = 86;
  } else {
    id = 96;
  }
});
```
You could have also done:
```onEvent(&quot;locationDropdown&quot;, &quot;change&quot;, function( ) {
  switch (getText(&quot;locationDropdown&quot;)) {
    case &quot;Anchorage, Alaska&quot;:
      id = 1;
    break;
    case &quot;Fairbanks, Alaska&quot;:
      id = 6;
    break;
    case &quot;Denver/Boulder, Colorado&quot;:
      id = 16;
    break;
    case &quot;Chicago Illinois&quot;:
      id = 31;
    break;
    case &quot;Des Moines, Iowa&quot;:
      id = 56;
    break;
    case &quot;Goodland, Kansas&quot;:
      id = 66;
    break;
    case &quot;Louisville, Kentucky&quot;:
      id = 86;
    break;
    default:
      id = 96;
    break;
  }
});
```
The ```switch statement``` is very useful in code because it saves time because you no longer have to write ```getText(&quot;locationDropdown&quot;)``` for every else if statement you write.
Anyways, I hope my answer helped at least a little. I wish you the best of luck!

Comment for this answer: Instead of a switch the question owner could also use a hash map/lookup table: https://medium.com/front-end-weekly/switch-case-if-else-or-a-lookup-map-a-study-case-de1c801d944

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:03/06/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><code.org>', 'Title': 'Code.org AppLabs: I am unable to get a specific whether condition on and display it on the screen', 'ViewCount': 61, 'id': 66511112, 'user_AboutMe': None, 'user_AccountId': 20888986.0, 'user_DisplayName': 'ToastedIce', 'user_Reputation': 11.0, 'user_Views': 0.0, 'user_id': 15344852.0}}