From 6add2285598992fb0b118222d3f87de9038cb4d1 Mon Sep 17 00:00:00 2001 From: galgluska <89578212+galgluska@users.noreply.github.com> Date: Mon, 13 Sep 2021 16:23:10 +0300 Subject: [PATCH 1/3] changes --- index.html | 4 +- scripts/index.js | 93 +++++++++++++++++++++++++++++++++++++++++++---- scripts/player.js | 2 + style.css | 29 +++++++++++++++ 4 files changed, 119 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index c55fb482..87aef6d4 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,9 @@
- + + +
diff --git a/scripts/index.js b/scripts/index.js index 6842c794..f0e59eaf 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -4,17 +4,29 @@ * * @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("p", title, [], {}), + createElement("p", album, [], {}), + createElement("p", artist, [], {}), + createElement("p", durationFormat(duration), [], {}), + createElement("img", [], [], { src: coverArt }), + ] const classes = [] - const attrs = { onclick: `playSong(${id})` } + const attrs = { onclick: `playSong(${id})`, id: "song" + id } return createElement("div", children, classes, attrs) } @@ -22,7 +34,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("p", name, [], {}), + createElement("p", [songs.length], [], {}), + createElement("p", playlistDuration(id), [], {}), + ] const classes = [] const attrs = {} return createElement("div", children, classes, attrs) @@ -34,14 +50,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