Function only grabbing the last index of the array in code.org program

I’m trying to help the kiddo with her AP project, her teacher said she can ask anyone for help, except her teacher. I went through her code but I don’t understand her program, I wanted to know if anyone in here could help out. Thankfully it’s not till May but she wants to do it early in case she runs into issues, and here we are. The website shes using is https://code.org/


I am having difficulty getting my code to grab my desired value from a dataset. I want it to grab a population level based on the location that the code outputs after the user selects their income in a dropdown. Once the user selects a certain income level, the app will provide a location by looking through the list and selecting a random country/territory that matches the income that has been selected.  I am trying to get the computer to grab the location given (after the income is selected and only if the income is selected as “High Income”) and use it to determine the correct population for that location. In other words, I want my append item to pull the population number from the randomly generated location given to the user after they input their income. After appending the item, I want my result to return the correct population for the location.

This is my else statement  
else if (incomeInput == "High Income")     appendItem(filterPopulation, finalDestination);     result = populationLevel[i];

“High income” is an income level option.
filterPopulation filters through my ‘PopulationLevel’ list
finalDestination is the location given after the user selects income
result is the string which I am using, trying to get it to return the population level for the location that the computer randomly selects after the income is given.

the result is currently only grabbing the index which I input into the [], or the last index if I just place [I].

var incomes = getColumn("Countries and Territories", "Income Level");
var populationLevel = getColumn("Countries and Territories", "Population");
var incomeInput = "";
var filterIncomeLevel = [];
var filterCountryName = [];
var filterPopulation = [];
var result = "";
var finalDestination = "";
setProperty("incomeLevelDropdown", "options", getColumn("Countries and Territories", "Income Level"));
hideElement("population");
hideElement("populationLabel");
onEvent("generateButton", "click", function( ) {
  filterIncomeLevel = [];
  filterCountryName = [];
  incomeInput = getText("incomeLevelDropdown");
  incomesList(incomeInput);
  setText("travelLocationOutput", randomLocation(filterCountryName));
});

function incomesList(incomeInput) {
  hideElement("population");
  hideElement("populationLabel");
  for (var i = 0; i < incomes.length; i++) {
  if (incomeInput==incomes[i]) {
      appendItem(filterIncomeLevel, incomes[i]);
      appendItem(filterCountryName, countryName[i]);
    } else if ((incomeInput == "High Income")) {
    showElement("population");
    showElement("populationLabel");
    appendItem(populationLevel, finalDestination);
    result = populationLevel[i];
  }
  }
}

function randomLocation(filterCountryName) {
  finalDestination = filterCountryName[(randomNumber(0,filterCountryName.length-1))];
  return finalDestination;
}


onEvent("dontKnow", "click", function( ) {
  setScreen("doNotKnowIncome");
});

// Found out how to do this from https://studio.code.org/projects/applab/pqdXRVMfu8QWW3-L1DO9FIh2RFQqWEG9O9qmQeRynyY/view
// Website is https://www.pewresearch.org/fact-tank/2020/07/23/are-you-in-the-american-middle-class/
onEvent("findIncomeButton", "click", function( ) {
  open("https://www.pewresearch.org/fact-tank/2020/07/23/are-you-in-the-american-middle-class/");
});

onEvent("backArrow", "click", function( ) {
  setScreen("inputsAndLocations");
});```