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 trialEdgar Sánchez
7,656 PointsBuild an Object Challenge Part 2, not working :(
Ok, so i tried to make this challenge on my own pc. I have my .html, and my 2 .js files, one for the students array and another for the code to print that data to the webpage. Didn't work and after testing and testing i've come to the conclusion that my data structure is wrong somehow, because when i copy and paste the one given in the course it works. The only difference i see is that Dave's array has the 'achievements' and 'points' properties for the 1st object as numbers, and the rest of the objects have them as strings. I don't get why since I understood these two pieces should always be numbers. So i don't know exactly what is wrong. I hope I made myself clear :/
This is Dave's array:
var students = [
{
name: 'Dave',
track: 'Front End Development',
achievements: 158,
points: 14730
},
{
name: 'Jody',
track: 'iOS Development with Swift',
achievements: '175',
points: '16375'
},
{
name: 'Jordan',
track: 'PHP Development',
achievements: '55',
points: '2025'
},
{
name: 'John',
track: 'Learn WordPress',
achievements: '40',
points: '1950'
},
{
name: 'Trish',
track: 'Rails Development',
achievements: '5',
points: '350'
}
];
This is my array:
var students = [
{
name: 'Edgar',
track: 'iOS Development';
achievements: 5,
points: 3016
},
{
name: 'Dory',
track: 'Design';
achievements: 2,
points: 516
},
{
name: 'Lucy',
track: 'Web Development';
achievements: 7,
points: 4623
},
{
name: 'Jason',
track: 'Javascript';
achievements: 6,
points: 1093
},
{
name: 'Morris',
track: 'Ruby';
achievements: 10,
points: 6546
}
];
Thanks again guys!
4 Answers
Dan Putnam
5,045 PointsYeah you have a semicolon after some of your object properties.
REMEMBER: if you ask a question online and then find the answer- don't just say 'I figured it out', say what you learned so you can help the next person.
Cosimo Scarpa
14,047 PointsThis is my solution with some explanation.
If you want to see how the code work.
http://codepen.io/coswise/pen/yMQqvR?editors=1010
var message = ""; // A an empty variable that we will fill up after with the loop.
var student;
// Array with objects.
var students = [
{
name : "David",
track: "Front End Developer",
point: 10342,
}, // Any Object need to be separate by a comma.
{
name : "Luis",
track: "Web Designer",
point: 1299,
},
{
name : "Aragon",
track: "iOS Developer",
point: 6123,
},
{
name : "Loren",
track : "Back End Developer",
point: 9001,
},
];
// standard function used for print.
function print(message) {
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = message;
}
// With this loop you will call any object in the array.
for ( var i = 0; i < students.length; i++ ) {
var student = students[i]; //This is just for create a shot solution for write student[0] and the others.
message += "<strong><p>Name : " + student.name + ".</p></strong>"; // A message for any component of the object.
message += "<p>Track : " + student.track + ".</p>";
message += "<p>Points : " + student.point + ".</p>";
message += "<br>"; // For make a little space between a student and another one.
}
print(message); // We are calling the function wrote above for print the text.
Edgar Sánchez
7,656 PointsNevermind already found the syntax error. -_- In any case the question would be: What syntax checking online service or something like that do you recommend?
Thnx
Edgar Sánchez
7,656 PointsAlright, thnx Colin, i'll check them out!