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 trialPeter Ajuzie
Full Stack JavaScript Techdegree Student 2,719 PointsHelp with housekeeping (line breaks)
Please I need some help with adding line breaks after each student object when it prints to the screen.
<p>
var students = [
{Name: 'Peter', Track: 'Front End Development', Achievements: 22, Points: 1545},
{Name: 'Paul', Track: 'iOS', Achievements: 19, Points: 1405},
{Name: 'Jude', Track: 'Web Design', Achievements: 10, Points: 890},
{Name: 'Lola', Track: 'Python', Achievements: 13, Points: 1032},
{Name: 'Tola', Track: 'Android', Achievements: 15, Points: 1198}
]
// ENCAPSULATE THE LOOPS IN A FUNCTION
function studentList( students ) {
for (var i = 0; i < students.length; i++) {
for (var prop in students[i]) {
student = document.write('<p>'+ prop + ': ' + students[i][prop] + '</p>');
}
}
}
// Call the function and print the list to the screen
studentList(students);
</p>
```
1 Answer
Steven Parker
231,236 PointsBy enclosing your outputs in paragraph tags you should get not only line breaks but some margin space between the lines. If you wanted only line breaks you could use <br>
instead of paragraphs:
document.write(prop + ': ' + students[i][prop] + '<br>');
And if you wanted an extra line in between students, you could write that in the outer loop:
for (var i = 0; i < students.length; i++) {
for (var prop in students[i]) {
document.write(prop + ': ' + students[i][prop] + '<br>');
}
document.write('<br>'); // extra line between students
}
Also, your script code seems to have some stray HTML (paragraph tags) at the beginning and end.
Peter Ajuzie
Full Stack JavaScript Techdegree Student 2,719 PointsThanks, Steven!
Per the stray html paragraph tags, I was still learning the markdown method for codes here lol. So forgot to delete them from the example html code from the cheatsheet.
Peter Ajuzie
Full Stack JavaScript Techdegree Student 2,719 PointsPeter Ajuzie
Full Stack JavaScript Techdegree Student 2,719 PointsI don't know if it's possible or perhaps my take of the challenge is too simplified?