# Cannot read property 'toString'

**URL:** <https://forum.code.org/t/cannot-read-property-tostring/34384>\
**Category:** Coding and Debugging Help\
**Tags:** csp-unit-5\
**Created:** [March 11, 2021, 7:24pm UTC](https://forum.code.org/t/cannot-read-property-tostring/34384 "2021-03-11T19:24:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![crjohnson](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@crjohnson](https://forum.code.org/u/crjohnson)\
**Post date:** [March 11, 2021, 7:24pm UTC](https://forum.code.org/t/cannot-read-property-tostring/34384/1 "2021-03-11T19:24:29Z")

</div>

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( ) {  
filter();  
updateScreen();  
});

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.

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [March 11, 2021, 11:34pm UTC](https://forum.code.org/t/cannot-read-property-tostring/34384/2 "2021-03-11T23:34:22Z")

</div>

Could you please share a link to the project?

---

<div class="post-metadata">

**Author:** ![crjohnson](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@crjohnson](https://forum.code.org/u/crjohnson)\
**Post date:** [March 12, 2021, 2:52am UTC](https://forum.code.org/t/cannot-read-property-tostring/34384/3 "2021-03-12T02:52:52Z")

</div>

> **[Check out what I made](https://studio.code.org/projects/applab/4HODieS67cadvA6DYXVEq8-DCHlDfAh0H6SFvVC8UO8)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![letti42](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@letti42](https://forum.code.org/u/letti42)\
**Post date:** [March 12, 2021, 3:14am UTC](https://forum.code.org/t/cannot-read-property-tostring/34384/4 "2021-03-12T03:14:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [March 12, 2021, 3:25am UTC](https://forum.code.org/t/cannot-read-property-tostring/34384/5 "2021-03-12T03:25:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![crjohnson](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@crjohnson](https://forum.code.org/u/crjohnson)\
**Post date:** [March 12, 2021, 5:29pm UTC](https://forum.code.org/t/cannot-read-property-tostring/34384/6 "2021-03-12T17:29:53Z")

</div>

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