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 trialDavid Pinner
7,039 Pointshave a look at my code, I've tried to use some ES6 and a different way to add the message
const students = [ { name: 'John', track: 'FullStack Developer', achievements: 20, points: 200 }, { name: 'Kate', track: 'ios', achievements: 60, points: 1000 }, { name: 'Alex', track: 'Javascript', achievements: 10, points: 20 }, { name: 'Jenifer', track: 'Front End Development', achievements: 45, points: 600 }, { name: 'Bob', track: 'BackEnd Development', achievements: 80, points: 2000 } ];
function printStudent(message) { document.getElementById('listAns').innerHTML = message; }
let mess = ''; let student;
for(let i = 0; i < students.length; i++) {
mess += ` <br>
<table>
<tr>
<td style="font-weight: bold">Name: ${students[i].name}</td>
</tr>
<tr>
<td>Track: ${students[i].track}</td>
</tr>
<tr>
<td>Achievements: ${students[i].achievements}</td>
</tr>
<tr>
<td>points: ${students[i].points}</td>
</tr>
</table>
`;
}
printStudent(mess);
1 Answer
Steven Parker
231,275 PointsGood use of the template string feature! I noticed that you declared (but didn't use) a "student" variable, but using it might be a nice way to make the template string a bit more compact:
for (let student of students) {
mess += `<br>
<table>
<tr><td style="font-weight: bold">Name: ${student.name}</td></tr>
<tr><td>Track: ${student.track}</td></tr>
<tr><td>Achievements: ${student.achievements}</td></tr>
<tr><td>Points: ${student.points}</td></tr>
</table>`;
}