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 trialMartina Carrington
15,754 Pointsmy song won't show
i probably did something wrong on the music player .
keep saying this on the JavaScript console a error Playlist.prototype.add = function(song) {
this.songs.push(song);
};
. now i have a blank music player
5 Answers
monty
9,167 PointsIn your playlist.js, add an (s) to this.song[i].toHTML(); so that your renderInElement will look like this:
Playlist.prototype.renderInElement = function(list){
list.innerHTML = "";
for(var i = 0; i < this.songs.length; i++){
list.innerHTML += this.songs[i].toHTML();
}
Martina Carrington
15,754 Pointsthanks Montensia Banks ,
monty
9,167 Pointslist.innerHTML += this.songs[i].toHTML();
Martina Carrington
15,754 PointsPlaylist.js music player
function Playlist() {
this.song = [];
this.nowPlayingIndex = 0;
}
Playlist.prototype.add = function(song) {
this.songs.push(song);
};
Playlist.prototype.play = function() {
var currentSong = this.songs[this.nowPlayingIndex];
};
Playlist.prototype.stop = function(){
var currentSong = this.songs[this.nowPlayingIndex];
currentSong.stop();
};
Playlist.prototype.next = function() {
this.stop();
this.nowPlayingIndex++;
if(this.nowPlayingIndex === this.songs.length) {
this.nowPlayingIndex = 0;
}
this.play();
};
Playlist.prototype.renderInElement = function(list) {
list.innerHTML = "";
for(var i = 0; i < this.songs.length; i++) {
list.innerHTML += this.song[i].toHTML();
}
};
Martina Carrington
15,754 Points@Hayley Swimelar
function Playlist() {
this.song = [];
this.nowPlayingIndex = 0;
}
Playlist.prototype.add = function(song) {
this.songs.push(song);
};
Playlist.prototype.play = function() {
var currentSong = this.songs[this.nowPlayingIndex];
};
Playlist.prototype.stop = function(){
var currentSong = this.songs[this.nowPlayingIndex];
currentSong.stop();
};
Playlist.prototype.next = function() {
this.stop();
this.nowPlayingIndex++;
if(this.nowPlayingIndex === this.songs.length) {
this.nowPlayingIndex = 0;
}
this.play();
};
Playlist.prototype.renderInElement = function(list) {
list.innerHTML = "";
for(var i = 0; i < this.songs.length; i++) {
list.innerHTML += this.song[i].toHTML();
}
};
Iain Simmons
Treehouse Moderator 32,305 PointsSo, looking at your code, it's actually that the array in the Playlist()
constructor function should have the s
on the end:
function Playlist() {
this.songs = [];
this.nowPlayingIndex = 0;
}
You'll then need to update any time where you're accessing this.song
and change it to this.songs
.
Also, you're missing the currentSong.play();
from the play
method:
Playlist.prototype.play = function() {
var currentSong = this.songs[this.nowPlayingIndex];
currentSong.play();
};
Hayley Swimelar
7,124 PointsHayley Swimelar
7,124 PointsCan you post your code so that we can have a better understanding of what might be wrong?