Question: This should be done in JavaScript You will be creating a custom object called catalogObject that will serve as a container for all of the
This should be done in JavaScript
You will be creating a custom object called catalogObject that will serve as a container for all of the song catalog functionality. This object will include catalog properties and methods. We will incrementally add and test functionality. Initially, we'll declare the catalogObject, declare an array property _songs initialized to an empty array, add method addSong(props) to add a song to _songs, and method listSongs() to list all of the songs in _songs:
-
_songs: empty array property
-
addSongs(props): Add a song to _songs, where method parameter props, short for properties, is a song object. The addSongs() method must use the String trim()
-
method to ensure the song title has no leading or trailing white space.
-
listSongs(): Iterates through _songs array and lists out the songs. You must use a template literal
-
to output the songs to the Console. Template literals make formatting multi-variable output easier.
console.log(`Name: ${position} - ${title}, ${artist} (${weeks})`);
Use the following steps to test catalogObject custom object
-
Create an instance of catalogObject:
const catalog = Object.create(catalogObject);
-
Load the catalog of songs by creating a for loop that iterates through the songs array, calling catalog.addSong() for each song in the songs array.
-
Call catalog.listSongs() to list each song in the songs array
Test your code changes by using the browser refresh button to reload catalog.html
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
