Hackathon Project - Need Help

Another request for help. I am hoping someone can help my student with her Hackathon app.

What’s expected: User chooses a genre from the selection, runs the app and it works as expected. User returns to the Home screen, chooses a different genre, runs the app and it is still returning part of the previous list instead of clearing it out. My students is using a watcher to see what is happening.

What she has tried: Using Clear in several of the onEvents.

She is confused and hoping to clear up the problem. Please let me know if you need more information than what I’ve provided. I am not 100% sure I’ve explained what she has tried to fix the problem accurately. Thanks!

@tcreager Hi again!
from what it seems you aren’t clearing the elements associated with what it’s set to, you could fix it with a setTimeout but I’ll just throw in a full clear example since that’s basically what you want

function clear(){
// EDIT: @jdonwells suggestion
  emptyFilteredLists();
  // modification starts here
  setText("bookRecommendationOutput", "");
  setImageURL("Image_of_book_recommended", "");
}

function emptyFilteredLists(){
  filteredTitleList = [];
  filteredAuthorList = [];
  filteredGenreList = [];
  filteredImageList = [];
}

by doing this you will basically get the same glimpse you were getting before, but both the text and image will be blank before updating,

Hope this helps Varrience

Another way to clear a list is to set it to a new empty list.

function emptyFilteredLists(){
  filteredTitleList = [];
  filteredAuthorList = [];
  filteredGenreList = [];
  filteredImageList = [];
}

To me, this expresses the intent more clearly.

1 Like

Thank you for your help. My student learned a new way that was not covered in our code.org lesson with help from varrience. When I shared the simplified code from you, I saw the light bulb moment. Thank you to both of you for your help!

1 Like

Love when that happens! Thanks for sharing :slight_smile: