-2
//clearing lists
function resetLists() {
 var finalColor = [];
 var finalDiet = [];
 var finalConservationStatues = [];
 var finalScientificName = [];
 var finalName = [];
}

this should be clearing/resetting the lists but it doesn't when called on in the program.I have tried calling the function in different parts of the program but it still doesn't work

1 Answers1

-1

If those variables are global, the following should work:

//clearing lists
function resetLists() {
 finalColor = [];
 finalDiet = [];
 finalConservationStatues = [];
 finalScientificName = [];
 finalName = [];
}

However, you can first test if the function can even "see" the variables you want to clear by adding a quick debug statement:

//clearing lists
function resetLists() {
 console.log("DEBUG: Can I see the following?");
 console.log(finalColor);

 finalColor = [];
 finalDiet = [];
 finalConservationStatues = [];
 finalScientificName = [];
 finalName = [];
}
Dr-Bracket
  • 4,299
  • 3
  • 20
  • 28