Music List


10 points



This app maintains a list of the user's top 10 favorite songs. It uses a list to store the names of the songs. You can declare a list like this:

var list = [];

You can access the 3rd element in the list in this way: list[3]. (Note that list[0] is actually the first element in the list. You don't have to start at 0, however; you can start at 1, which is what I did for this program.)

You insert an element into the list like this: list[4] = song;

There are other list functions that you probably won't need here. 'appendItem()' adds an item to the end of the list. 'insertItem()' adds an item to the list. 'removeItem()' removes an item from the list.

When a user enters a new song, indicates which position it should occupy in the list and clicks the button, an onEvent() runs. The app enters the new song at that position in the list.

I wrote a function setUpList() that stores an empty string (" ") in each of the 10 positions of the list. You can write a FOR loop for this. This function is called once when the user first clicks the button.

I wrote a second function displaySongs() that displays the 10 songs in the Text Area. This function uses a FOR loop to transfer the contents of the list into 1 string that is then displayed. The "\n" is a linefeed character that is used to move the output to the next line. This function is called in the onEvent() that runs when the button is clicked.




The video shows what a completed app should do.