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 trialReza Sorasti
491 PointsA few questions on creating Javascript objects.
Below we have an array of objects.
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'
}
];
My questions is why is it that in the array each object has no name, but if I were to create an object outside of an array, then I have to give it a name like person(like below)?
var person = {
name : 'Sarah',
country : 'US',
age: 35,
treehouseStudent : true,
skills : ['JavaScript', 'HTML', 'CSS']
};
Thanks
9 Answers
Steven Parker
231,271 PointsAssigning the object to the variable "person" gives you a name you can use to reference it later. In the first example, this is done by assigning the entire array to the variable "students", which can be used with an index to reference the individual objects inside it.
Whether an individual or collection (array), you still have a named variable that you can use to reference the object(s).
Happy coding!
Reza Sorasti
491 PointsThanks Steven
Reza Sorasti
491 PointsHey Steven, do you have an email? I need to send you a questionn.
Steven Parker
231,271 PointsIt's probably not a good idea to post an email address in an open forum like this. But you can ask a question here.
Reza Sorasti
491 PointsIn the bottom of your response, you said, "happy coding!" I was just wondering what you mean by that. It is impossible to be happy every time I write code or deal with code. Were you telling me to be happy every time I do coding when you wrote, "happy coding!"?
Steven Parker
231,271 PointsI use the phrase "Happy coding" as a programmer version of "best wishes" or "have a nice day". It's not meant as either a prediction or an instruction. But I'm hopeful that you will enjoy your coding experiences.
Reza Sorasti
491 PointsThanks for your response. But, I get things the best with simple response of either Yes or No when it comes to topics like that.
Just to make sure that I understood your response.
1) When you wrote, "happy coding!", were you telling me to be happy every time I do coding?
2)Also, it is impossible to enjoy my coding experience every time I code. Some times I do. Some times I don't. When you wrote, "I'm hopeful that you will enjoy your coding experiences.", were you telling me I have to enjoy my coding experiences every time I do coding?
I will choose your original response as best answer after your replay to my two questions in this post.
I am asking for a simple "Yes" or "No" response to my two above questions.
Steven Parker
231,271 Points- No
- No
But I do hope you'll enjoy coding (more often than not).
Reza Sorasti
491 Points3) What do you mean by, "I do hope you'll enjoy coding (more often than not)"? 4) Are you telling me I have to enjoy coding? 5) What do you mean by "more often than not"? 6) Will I be disobeying you if don't enjoy coding more often when I code than less often?
Just for your information, the reason I ask this questions is because I have a religious obsession of obeying people.
Steven Parker
231,271 PointsThese are a bit more than "yes or no" questions.
Ā 3) It just means I'm being friendly.
Ā 4) You certainly don't have to enjoy it. I only hope you will.
Ā 5) It means I hope you'll have more "Some times I do." experiences than the "Some times I don't" ones.
Reza Sorasti
491 Points6) Will I be disobeying you if I don't enjoy coding more often when I code than less often? 7) My English is not perfect. When you say, "I only hope you will", are you telling me, I have to enjoy coding more often when I code then less often?
Steven Parker
231,271 Points6) No.
7) No.
Chris Freeman
Treehouse Moderator 68,454 PointsHi Reza Sorasti, perhaps there is a cultural gap in this discussion of expressions used in closing correspondences.
For example, "best wishes" is defined as An expression of hope for someone's future happiness or welfare, often written at the end of a letter. It is a positive gesture of friendship. It is not a command or instruction and contains no obligations.
As Steven has mentioned, "happy coding" is intended to be of the same spirit, as is "happy hacking", "good luck", "happy travels", "travel well", etc.
Out of curiosity, how would you close an informal letter to friend that you wish happy success upon?
Reza Sorasti
491 PointsIf I am write it in Farsi would probably say, "barkateh khodavand ba shoma", which would translate to God bless which is a prayer for the person to get blessed. That way the person does not feel obligated to do any thing regarding what I say at the end of the letter.
Chris Freeman
Treehouse Moderator 68,454 PointsThank you for that explanation. It is with the same good intentions that Steven meant when he used "happy coding".
Reza Sorasti
491 PointsYou are welcome!
Reza Sorasti
491 PointsHi Steven,
In my other post that was called Test, unfortunately, that post was deleted by the moderator before I even read your response to my final two questions. So, I am going to ask them here and hopefully you can see them and get back to me on them. A yes or no response is all I need:
1) In that post, you wrote to me using the phrase, āAs I said beforeā, by using this phrase, āAs I said beforeā were you telling me to not repeat myself?
2) In the future, when I am alone, I might sometimes need to repeat myself (both verbally and\or action wise). Is it ok with you that in the future I repeat things to myself or to God or to both God and myself as much as I want(both verbally and\or action wise)?
3) I would like to repeat things like repeat studying or repeat exercising or repeat many other things in life. Is it ok with you that in the future I repeat things as much as I want?
4) Just for my own knowledge, in the future if someone tells me or write me, āAs I said beforeā, is that person telling me to Not repeat myself when I am alone?
Thanks for answering my questions.
Rich Donnellan
Treehouse Moderator 27,696 PointsRich Donnellan
Treehouse Moderator 27,696 PointsAdded formatting to the question. Consider doing so next time for code legibility.