I’m doing the exercises for certifications and I believe there’s a little bug in the code.
There’s a userData object with a userData.songCurrentTime field
let userData = {
songs: [...allSongs],
currentSong: null,
songCurrentTime: 0,
};
In the pauseSong arrow function you have to store the audio.CurrentTime in the userData.songCurrentTime
const pauseSong = () => {
userData.songCurrentTime = audio.currentTime;
And in the playSong arrow function you have an if statement:
if (userData?.currentSong === null || userData?.currentSong.id !== song.id) {
audio.currentTime = 0;
} else {
audio.currentTime = userData?.songCurrentTime;
}
so if the id of the song is diferent you start by the currentTime = 0 , otherwise you continue from the songCurrentTime stored in userData when pausing.
The problem is that there’s other function renderSongs that creates a button with an onclick event calling playSong(${song.id}) without setting userData.songCurrentTime to 0 nor saving the userData.songCurrentTime again, so if you pause a song , then every time you click again the same song it starts over from the same songCurrentTime stored when it was originally paused, at least until you change the song and reset the time.
<button class="playlist-song-info" onclick="playSong(${song.id})">
I think it’s not a desired behaviour, but not sure.
Thanks! I’m really enjoying freeCodeCamp