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 trialStefan Cutajar
7,747 PointsWhy list is printing an extra blank line?
Hi, For some reason my code is skipping a line after every list item. I checked the code with the one of Dave's in the video but I can`t find whats wrong.
var playList = [
'I Did It My Way',
'Respect',
'Imagine',
'Born to Run',
'Louie Louie',
'Maybellene'
];
function print(message) {
document.write(message);
}
function printList(list){
var ulist = "<ol>";
for (var i=0; i < list.length; i += 1){
ulist += "<li>" + list[i] + "<li>";
}
ulist += "</ol>";
print(ulist);
}
printList(playList);
Moderator Edit: Corrected Markdown so the code block is readable in the Community. Please refer to the Markdown Cheatsheet (located above the Post tab), or have a look at the Markdown Basics course here on Treehouse.
3 Answers
Steven Parker
231,275 PointsI notice that the ending tag for the list items is missing a slash:
ulist += "<li>" + list[i] + "<li>"; // original
ulist += "<li>" + list[i] + "</li>"; // fixed
The extra starting tag created an empty list item after each intended one.
For future issues, you can use the snapshot function in the workspace and provide the link to it to facilitate a complete analysis while saving posting space and providing code with original formatting.
Stefan Cutajar
7,747 PointsThanks a lot :D Any idea of how can I debug in similar cases like this because there wasn't any information given in the console.
Steven Parker
231,275 PointsIn this case the best tool is the "calibrated eyeball" since an undefined property is simply "undefined" and not an error.
There might be some other code-checking tools that would detect it but I tried this in my favorite (JsHint) and it also did not show it as an error.
Stefan Cutajar
7,747 PointsThanks I didn't know about JsHint I think it maybe introduced later in the course it looks like a good tool when debugging :)
Stefan Cutajar
7,747 PointsStefan Cutajar
7,747 PointsThanks I did not catch that. I tried to write it again but this time nothing shows can you take a look for me please? https://w.trhou.se/s2cyt7bzbe
Steven Parker
231,275 PointsSteven Parker
231,275 PointsThis time it's the spelling of "lentgh" instead of "length" on line 16.