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 trial
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsBuild an object challenge part 2
Hi guys I have a few questions.
- in the second part of the build an object challenge Dave McFarland created a new javaScript file to hold the program that will print the message out to the screen. How is it possible that the new javaScript file is able to access the names of the variables in the other js file when the two files aren't linked. Yes the two files are in the index.html file and run one after the other but the names of the variables in the first js file are called in the second js file when the two files aren't linked. He didn't mention that that was possible in previous lessons. How is the second js file able to use the names that are in the firls js file.
- in the instructions video he told us that for example we created an array and named it students. To get to the first student object you'd use bracket notation and an index value of 0, like this students[0]. Then to get to the name of that student we would add on the name property like this students[0].name. however in the solution video, that's not how he did it. he first created a student variable and gave it a value of students[i] then he created a message string and concatenated each item in the object with the .name property. I assumed that the example he gave all goes on one line. like he did in the video.
- why did he first create a message variable and gave it an empty string?
explanation video: https://teamtreehouse.com/library/javascript-loops-arrays-and-objects/tracking-data-using-objects/the-build-an-object-challenge-part-2
solution video: https://teamtreehouse.com/library/javascript-loops-arrays-and-objects/tracking-data-using-objects/the-build-an-object-challenge-part-2-solution
1 Answer
Steven Parker
243,656 Points- The two files are linked when they are both loaded into the same page by the index.html file.
- (what is the question here?)
- Before you can use it in concatenation, the message must have something assigned to it, even an empty string.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsSAMUEL LAWRENCE
Courses Plus Student 8,447 PointsOk, thanks Steven Parker today I'm just feeling a bit overwhelmed, I guess. Seemed very lost today as I came to the end of the course. I tried to complete the last 3 challenges over a couple of hours, I was only able to complete the first part. I got 1/4 way in the second and 1/3 way in the third. I knew I wouldn't have been able to complete a working program even if I spent days on it and I was right. My thinking just haven't expanded sufficiently enough yet. I have to go over this and practice. Thanks for your rapid responses as usual.
Steven Parker
243,656 PointsSteven Parker
243,656 PointsYou might enjoy this episode of The Treehouse Show that discusses temporary learning blocks and strategies for dealing with them (including suggestions by me!).
Happy coding!