Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,34 @@ const player = {
{ id: 1, name: 'Metal', songs: [1, 7, 4] },
{ id: 5, name: 'Israeli', songs: [4, 5] },
],
//function that looks for a song with a certin id in an array of songs.
//and "plays" it.
playSong(song) {
console.log(/* your code here */)
let ans; // var to store the song with the right id.
// search for the song in the array.
this.songs.forEach(check => {
if(check.id == song)
ans = check;
});
let mmDuration;
let ssDuration;
try {
//calculate the duration in mm:ss format.
mmDuration = Math.floor(ans.duration / 60);
if(mmDuration < 10)
mmDuration = "0" + mmDuration;
ssDuration = ans.duration - mmDuration * 60;
//log the song in the right format.
console.log(`Playing ${ans.title} from ${ans.album} by ${ans.artist} | ${mmDuration}:${ssDuration}.`);
} catch (error) {
//exception handling.
console.log("error playing this song");
}
},
}

function playSong(id) {
// your code here
player.playSong(id);
}

function removeSong(id) {
Expand Down Expand Up @@ -92,6 +113,7 @@ function searchByDuration(duration) {
// your code here
}


module.exports = {
player,
playSong,
Expand Down
Loading