Cannot read property 'toString'

I have a student who is trying to display in a text box the element that was selected by random from a filtered list. I am not sure where the error is occurring. I have tried everything I know. Can someone please help?

//purpose: sets up base data lists
//explain: sets data as lists from data set to store in variables
var artistNames = getColumn (“RollingStone: 500 Albums”, “Artist”);
var albumNames = getColumn (“RollingStone: 500 Albums”, “Album”);
var genreList = getColumn (“RollingStone: 500 Albums”, “Genre”);
var yearList = getColumn (“RollingStone: 500 Albums”, “Year”);
var albumArtList = getColumn (“RollingStone: 500 Albums”, “Album Art”);

//purpose: sets up blank lists
//explain: these filtered lists will be comprised of what the genre
//input selection determines to be put into them
var filteredArtists = ;
var filteredAlbums = ;
var filteredYear = ;
var filteredArt = ;

//purpose: changes screen
//explain: when dropdown is changed, functions are performed
onEvent(“genreInput”, “change”, function( ) {

function filter() {
//reset filtered lists to empty
filteredArtists = ;
filteredAlbums = ;
filteredYear = ;
filteredArt = ;

//traverses genre list
//if genre matches the input option, songs of that genre will be displayed
for(var i=0; i<genreList.length; i++){
var genreChoice = getText(“genreInput”);
if(genreList[i] == genreChoice){
appendItem(filteredArtists, artistNames[i]);
appendItem(filteredAlbums, albumNames[i]);
appendItem(filteredYear, yearList[i]);
appendItem(filteredArt, albumArtList[i]);

function updateScreen(){
var index = randomNumber(0, filteredArtists.length-1);
setText(“artist”, filteredArtists[index]);
setText(“albumName”, filteredAlbums[index]);
setNumber(“year”, filteredYear[index]);
setProperty(“albumArt”, “image”, filteredArt[index]);

The error is occuring in the setText(“artist”, filteredArtists[index]); line.

Could you please share a link to the project?

What I can make out from this is that it says you haven’t defined the array filteredArtist to anything, which you have. This looks to be an error with your function, but I haven’t seen an error like this before as everything looks to be correct.

1 Like

The genres in the drop down menu do not match the genres in the table. For example, there is no genre “Blues Rock” which is the first item in the dropdown menu. It should be “Rock, Blues”. The case on other items also does not match (“electonic” vs. “Electronic”). So, when comparing genreList[i]== genreChoice, one should set them both to the same case like genreList[i].toLowerCase() == genreChoice.toLowerCase(). Since no matching genre is found in the data set, the filteredArtists list is empty. When it is used in setText, it gives an error.


Thank you! This solved our problem. I will keep an eye out for that issue in the future.