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 trialKristjan Vingel
7,992 PointsMy solution (trying to use modern JS)
let html = "";
const students = [{
name: "John",
track: "iOS",
achievements: 111,
points: 102124342
},
{
name: "Mary",
track: "Web Design",
achievements: 222,
points: 20353536363
},
{
name: "Richard",
track: "Android",
achievements: 555,
points: 543243243240
},
{
name: "Elisa",
track: "Full Stack",
achievements: 777,
points: 902343242
},
{
name: "Alice",
track: "Front End",
achievements: 333,
points: 8232424424240
}
];
function print(message) {
let outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
for (let x in students) {
html += `<h2>Student: ${students[x].name}</h2>
<ul>
<li>Track: ${students[x].track}</li>
<li>Points: ${students[x].points}</li>
<li>Achievements: ${students[x].achievements}</li>
</ul>`;
}
print(html);
1 Answer
Jamie Reardon
Treehouse Project ReviewerNice stuff! You could even go further with the newer syntax by converting your function to an arrow function, like so:
const print = message => {
let outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
The only other thing (being nit-picky as I am not sure if you are doing this to improve the look of the code more?) is that you could also clean up the template literal string by indenting the code like so:
for (let x in students) {
html += `
<h2>Student: ${students[x].name}</h2>
<ul>
<li>Track: ${students[x].track}</li>
<li>Points: ${students[x].points}</li>
<li>Achievements: ${students[x].achievements}</li>
</ul>`;
}
Ryan Soeder
11,056 PointsRyan Soeder
11,056 PointsThis is a beautiful solution but will a for...in loop work on "students" given that it's an array and not an object?