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 trialTage Smith
2,997 PointsFor some reason this won't work
The first, fifth and sixth bracket in my array stays green. And when I look at it in it's form it doesn't print. What gives
var playList = [
['I Thnk We're Alone Now','The Rubinoos'],
['Easy Street', 'Eddie Howell'],
['Kaleidoscope','Kaleidoscope UK'],
['Come Back Jonee','Devo'],
['Peter's Birthday','World of Oz'],
['L'Education', 'Aline']
];
function print(message) {
document.write(message);
}
function printSongs( songs ) {
var listHTML = '<ol>';
for ( var i = 0; i < songs.length; i += 1) {
listHTML += '<li>' + song[i][0] + ' by ' + song[i][1] + '</li>';
}
listHTML += '</ol>';
print(listHTML);
}
printSongs(playList);
Tage Smith
2,997 PointsHow do I format it again?
Ted Sumner
Courses Plus Student 17,967 PointsLook at the Markdown Cheatsheet or you can edit your post to see what I did.
7 Answers
Ted Sumner
Courses Plus Student 17,967 PointsIn your for loop you switch from songs to song. Add the s to song in your two variables and it works.
I found the error by copying and pasting the code into the JavaScript console and running it. It gave me errors that pointed to the solution.
Samuel Webb
25,370 PointsGood find
Tage Smith
2,997 PointsThanks for reminding me to use the console.
Samuel Webb
25,370 PointsYou're using apostrophes in your strings while also using single quotes to contain them. Use double quotes to contain your strings and you'll bypass that issue.
Samuel Webb
25,370 Pointsvar playList = [
['I Thnk We\'re Alone Now','The Rubinoos'],
['Easy Street', 'Eddie Howell'],
['Kaleidoscope','Kaleidoscope UK'],
['Come Back Jonee','Devo'],
['Peter\'s Birthday','World of Oz'],
['L\'Education', 'Aline']
];
function print(message) {
document.write(message);
}
function printSongs( songs ) {
var listHTML = '<ol>';
for ( var i = 0; i < songs.length; i += 1) {
listHTML += '<li>' + song[i][0] + ' by ' + song[i][1] + '</li>';
}
listHTML += '</ol>';
print(listHTML);
}
printSongs(playList);
There you go. That looks about right. I chose to escape the apostrophes instead of using double quotes to make it easier on myself.
Tage Smith
2,997 PointsAlso, how do I put this code into proper html boxes again?
Ted Sumner
Courses Plus Student 17,967 PointsThe ' in Peter's is causing you problems. Try changing to this:
'Peter\'s Birthday'
You also have the same problem in L'Education.
Ted Sumner
Courses Plus Student 17,967 PointsI see some other ' issues now. You either have to use " to surround the text when you use ' as part of the text or escape it with .
Tage Smith
2,997 PointsI replaced single quotes with double, and it still won't print.
Ted Sumner
Courses Plus Student 17,967 PointsPlease post your new code.
Tage Smith
2,997 Points'''html var playList = [ ['I Thnk We're Alone Now', 'The Rubinoos'], ['Easy Street', 'Eddie Howell'], ['Kaleidoscope','Kaleidoscope UK'], ['Come Back Jonee','Devo'], ['Peter\ 's Birthday','World of Oz'], ['L\ 'Education', 'Aline'], ];
function print(message) { document.write(message); }
function printSongs( songs ) { var listHTML = '<ol>'; for ( var i = 0; i < songs.length; i += 1) { listHTML += '<li>' + song[i][0] + ' by ' + song[i][1] + '</li>'; } listHTML += '</ol>'; print(listHTML); }
printSongs(playList); '''
Ted Sumner
Courses Plus Student 17,967 PointsUse the back ticks on the upper left corner of your keyboard, then your quote should look right. Another thing is that you have to double space between any text prior to the quote and the line with the `.
Ted Sumner
Courses Plus Student 17,967 PointsAlso, this is JavaScript, not HTML, so you would put JavaScript after the first set of ticks.
Tage Smith
2,997 PointsWhoops I was using single quotes.
Ted Sumner
Courses Plus Student 17,967 PointsIt took me a long time to figure out how to do it right. I have suggested a mandatory video on forum posting. It doesn't exist yet, but I hope it does soon.
Tage Smith
2,997 Points'''html var playList = [ ['I Thnk We're Alone Now', 'The Rubinoos'], ['Easy Street', 'Eddie Howell'], ['Kaleidoscope','Kaleidoscope UK'], ['Come Back Jonee','Devo'], ['Peter\ 's Birthday','World of Oz'], ['L\ 'Education', 'Aline'], ];
function print(message) { document.write(message); }
function printSongs( songs ) { var listHTML = '<ol>'; for ( var i = 0; i < songs.length; i += 1) { listHTML += '<li>' + song[i][0] + ' by ' + song[i][1] + '</li>'; } listHTML += '</ol>'; print(listHTML); }
printSongs(playList); '''
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsEdited to format quote. The formatting helps highlight the problem.