Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Elston
8,112 PointsWhere in this code is class ="current" being removed from the currently playing song before it's added to the next song?
Andrew's code works, but mine seems behave differently; the pink highlighting over the playing song gets added to the next song when the next button is pressed, but also remains on the last song. After inspecting with the Dev tools it seems they both retain the class="current" value. Where does Andrew's code deal with this?
3 Answers
rydavim
18,814 PointsWhether or not a song should have the 'current' class attached is dealt with in the Song.prototype.toHTML function with an if structure.
// It should look something like this...
if(this.isPlaying){
htmlString += ' class="current"'; // If the song is playing, add the class current.
}
// When a song is stopped, isPlaying should be set to false.
Song.prototype.stop = function() {
this.isPlaying = false;
};
Playlist.prototype.next = function() {
this.stop(); // The first thing the next function does is stop the current song.
// . . .
};
If you're still seeing this behavior after looking into these code snippets, you could post your solution and we can see if we can't figure out what's going wrong. Happy coding!
Iain Simmons
Treehouse Moderator 32,305 PointsDid you remember to run the playlist.renderInElement(playlistElement);
code in each of the onclick
handlers? He mentioned that you need to render the HTML again...
var playButton = document.getElementById('play');
playButton.onclick = function() {
playlist.play();
playlist.renderInElement(playlistElement);
}
var nextButton = document.getElementById('next');
nextButton.onclick = function() {
playlist.next();
playlist.renderInElement(playlistElement);
}
var stopButton = document.getElementById('stop');
stopButton.onclick = function() {
playlist.stop();
playlist.renderInElement(playlistElement);
}
Also make sure that you're resetting the innerHTML
property before changing it:
list.innerHTML = "";
Andrew Gursky
12,576 PointsI had the same issue. The solution for me was that in my Playlist.next function I had written this.stop instead of this.stop(). Maybe you did the same? Check your parenthesis.