diff --git a/index.html b/index.html index c55fb482..aae65b9f 100644 --- a/index.html +++ b/index.html @@ -9,9 +9,14 @@ + +
- +
Mp3 Player
+ +
+
diff --git a/index.new.html b/index.new.html index eba39f17..3a44588b 100644 --- a/index.new.html +++ b/index.new.html @@ -9,20 +9,9 @@ -

Awesome Player!!!

-
-

Add a new song

-
- - - - - -
- -
-
-

Songs

+
+
+

Mp3 Player

+
+

Add a new song

+
+ + + + + + +
+ +
+ +
diff --git a/scripts/index.js b/scripts/index.js index 6842c794..0868a749 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -4,17 +4,30 @@ * * @param {String} songId - the ID of the song to play */ -function playSong(songId) { - // Your code here + + function playSong(songId) { + for (let song of player.songs) { + document.getElementById("song" + song.id).classList.remove("playing") + if (song.id === songId) { + document.getElementById("song" + song.id).classList.add("playing") + } + } } /** * Creates a song DOM element based on a song object. */ function createSongElement({ id, title, album, artist, duration, coverArt }) { - const children = [] + const children = [ + createElement("img", [], [], { src: coverArt }), + createElement("span", title +" | ", [], {}), + createElement("span", album+" | ", [], {}), + createElement("span", artist+" | ", [], {}), + createElement("span", durationFormat(duration), ["duration"], {}, ), + + ] const classes = [] - const attrs = { onclick: `playSong(${id})` } + const attrs = { onclick: `playSong(${id})`, id: "song" + id } return createElement("div", children, classes, attrs) } @@ -22,7 +35,11 @@ function createSongElement({ id, title, album, artist, duration, coverArt }) { * Creates a playlist DOM element based on a playlist object. */ function createPlaylistElement({ id, name, songs }) { - const children = [] + const children = [ + createElement("span", name+" | ", [], {}), + createElement("span", [songs.length], [], {}), + createElement("span", playlistDuration(id), ["duration"], {}), + ] const classes = [] const attrs = {} return createElement("div", children, classes, attrs) @@ -34,14 +51,75 @@ function createPlaylistElement({ id, name, songs }) { * Example usage: * createElement("div", ["just text", createElement(...)], ["nana", "banana"], {id: "bla"}) * - * @param {String} tagName - the type of the element - * @param {Array} children - the child elements for the new element. + * @param {String} tagName - the type of the element: for example- p,h1,div... + * @param {Array} children - the child elements for the new element: for example- assume ew have