List ALL the properties!


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/objects-ii/1/5?curriculum_id=506324b3a7dffd00020bf661#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Hello all. I’ve been on the site for a bit over a month and enjoying it. There have been several places I’ve been stuck along the way and figured them out thanks to this forum or other references.
This being said, I find myself at times trying to better understand the logic behind the code (why it worked, or didn’t). The code in this exercise is an example. It worked, however I would like to better understand why. Specifically why with only one variable called did it log all to the console? My guess is that the code just runs down the list starting at the first variable which was called in my loop and went down the lines but I’m not sure.
Good to be here and I’m sure someone more skilled/experienced can explain this; thanks in advance.

```

var nyc = {
fullName: “New York City”,
mayor: “Bill de Blasio”,
population: 8000000,
boroughs: 5
};

var f = “fullName”;
var m = “mayor”;
var p = “poulation”;
var b = “boroughs”;

// write a for-in loop to print the value of nyc’s properties
for (var f in nyc) {
console.log (nyc[f]);
}

<do not remove the three backticks above>

#2

its the for in loop, it will (in order) assign each property of object to the loop iterator (f in your case)


#3

Great to know. It’s quite useful to understand how certain aspects work for future reference and to learn.
Thank you for the prompt feedback and clarity.


#4

MDN always has good documentation for more in-depth understanding:


#5

That looks like a great resource, I’ll check it out in depth. I’m new to coding am amazed by the amount of resources and helpful people. I use Firefox and recently cane across the MDN site and amazed by the volume of info.
Thanks again for the detailed information regarding my specific query.


#6

Programmers are a weird bunch, there is so much documentation and free open source software (see github)

So many programmers share great things for free, it super weird. So far i know, there is no other proffession which even gets closed to the amount of sharing programmers do

open source = the code is aviabable (for example on github) so you can install it, and modify it

someone wrote a python script which allowed you to right click a video file and download subtitles for movies and tv series, its amazing


#7

That is great, sounds like a really cool program.
This reminds me of a book I recently read (Flash Boys by Michael Lewis) true story. One of the main characters was a great Russian programmer building software for hft (high frequency trading). He designed his algorithm and downloaded code ( open source) to complete his program. He emailed this code to himself to remember how he did it & wouldn’t have to find it again if needed. This was fine until he left the bank he was working for. They pursued criminal charges over this open source code claiming it became their property once it was in their machines. He went to jail and was later released over greed and the justice system being clueless about any of this tech(open source, sharing nature of programmers…).
Perfect example of what you’re saying about how different and open programmers are vs virtually every other industry.
Refreshing to me, I can much better relate to this mindset; share the knowledge, build the community=progress. It will be nice when I can contribute.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.