JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2 Solution

Karol Gutkowski
Karol Gutkowski
5,563 Points

Same result not sure if what i did is anything like bad practice or something else?

I've got the same results but just wanted to ask if the solution i found is correct and things i did aren't considered bad practice?

for(var i = 0; i < students.length; i += 1){ print('<h2>Student: '+ students[i].name + '</h2>'); print('<p>Track: '+ students[i].track + '</p>'); print('<p>Points: '+ students[i].points + '</p>'); print('<p>Achievements: '+ students[i].achievements + '</p>'); }

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,854 Points

I'm not sure what you mean by same results. Every time you call print you reassign the innerHTML of the output div. Since you loop through all students calling print for each property you will only display the achievements of the last student.

Karol Gutkowski
Karol Gutkowski
5,563 Points

My bad i didn't show my print function: function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML += message; }

And if im not wrong it adds to the value so in the end result is the same;