Learn

We often want to know how many items an array contains. We can do this with the .Length property.

int[] plantHeights = { 3, 4, 6 }; // arrayLength will be 3 int arrayLength = plantHeights.Length

Using the .Length property will return the number of items in an array and zero if the array is empty.

Instructions

1.

Each playlist can only have eight songs, so we want to write a program that checks to make sure that there are the right amount of songs.

If there are eight songs in the playlist, have the console print out a message that lets the user know the playlist is complete, like “summerStrut Playlist is ready to go!”

2.

If a user tries to add more than eight songs to a playlist, write them a message that their playlist will be rejected for being too long. You can write something like, “Too many songs!”

To check that it works, add another song to the array.

3.

If there are less than eight songs in the playlist, let the user know that they should add more songs. You can write something like, “Add some songs!”

To check that it works, delete songs from the playlist.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?