Skip to content

function prevents rest of code from working

function updateScreen() {
  var textOutput = "";
  setScreen("yellowScreen");
  for (var i=0; i < finalColor.length; i++){
    var newIndex = i+1;
    textOutput = (((textOutput + newIndex +". NAME: " +finalName[i] + ", " 
+ "scientific name is") + finalScientificName[i] + ", " + "this bird is 
")+ finalConservationStatues[i] + "and they eat ")+ finalDiet[i]+"nn";
  }
  setText("yellowOutput", textOutput);
  console.log(textOutput);
}

onEvent("yellowButton", "click", function( ) {
 yellowFilter();
 upDateScreen();
});

the function yellowFilter prevents anything else to run

function yellowFilter() {


for (var i = 0; color.length; i++) {
if (color[i] == 'Yellow' ) {
  appendItem(finalColor, color[i]);
  appendItem(finalDiet, diet[i]);
  appendItem(finalConservationStatues, conservationStatus[i]);
  appendItem(finalScientificName, scientificName[i]);
  appendItem(finalName, Name[i]);
  console.log(finalColor);
   }
  }
 }

is there anything wrong with these functions the update screen function doesn’t run if the yellowFilter runs but yellowFilter needs to run so that upDateScreen can run properly

Answer

Without actually going through anything I see one error immediately: for (var i = 0; color.length; i++)

The second statement in a for loop needs to be a conditional