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 trialCandace Cohen
Courses Plus Student 2,120 PointsCannot read property 'add' of undefined
I keep getting an error in regards to the playlist.add but I am not sure what I am doing wrong? var playlist = Playlist ();
var giveItToYou = new Song ("Give it to you", "Robin Thicke", "3:50");
var fancy= new Song("Fancy", "Iggy Azalea", "3:20");
var wiggle= new Song("Wiggle", "Jason Derulo", "3:20");
var upDown= new Song("Up Down", "T-pain", "3:52");
var bringTheNoise= new Song("Bring the Noise", "M.I.A", "3:24");
var goGirl= new Song("Go Girl", "Ciara", "3:56");
playlist.add(giveItToYou); playlist.add(fancy); playlist.add(wiggle); playlist.add(upDown); playlist.add(bringTheNoise); playlist.add(goGirl);
var playlistElement = document.getElementById("playlist");
playlist.renderInElement(playlistElement);
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); }
1 Answer
Amy Norris
9,718 PointsI think you need "new" before "Playlist()" near the top.
var playlist = new Playlist ();
Candace Cohen
Courses Plus Student 2,120 PointsCandace Cohen
Courses Plus Student 2,120 PointsThat cleared it. Thanks!