Not sure how to post code to ask question

So i know there is a proper way to post code on here that I have a question about. I remember I need to use the backticks before and after the code. Is there anything else I need to do ?

Start with asking. Donā€™t ask to askā€¦ just ask. Weā€™ll guide you, if we need clarification.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The ā€œpreformatted textā€ tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

1 Like

also, your current code, the challenge link, or instructions of what you need to do (exactly as writte ), what you think the challenge is asking you to do, failing tests, what you understand and not understandā€¦
also, describing what you think each piece of code is doing (commenting your code even if you donā€™t need to ask a question is good practice)
these are all things that let you ask a better question and so get a better answer

1 Like

Okay thank you. And first let me also thank you for being quick to respond. And always being here.

So I dont always word questions correctly, but like everything else I am working on it.
But in the Basic Data Structures: Iterate Through the Keys of an Object with a forā€¦in Statement challenge.
I am wondering how the word name is recognized or understood in the program, I guess with out it being defined.

  Alan: {
    age: 27,
    online: false
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};

function countOnline(obj) {
  // change code below this line
let count = 0;
for (let name in users){
  if (users[name].online === true){
    count ++;
  }
}
return count;
  // change code above this line
}```

console.log(countOnline(users));`
How dose it understand ` (let name in users`   or `users[name]
Also it still says to wrap  in backticks I thought I did. So I apologize cant seem to get it rite
1 Like

Thank you for your response and help. It is much appreciated.

Youā€™re fine, no worries. Perfectly understandable question. Letā€™s break it down.

First, the top-level object, users, looks like this (just the root object and itā€™s own direct properties):

users = {
  Alan:      /* user sub-object */,
  Jeff:      /* user sub-object */,
  Sarah:     /* user sub-object */,
  Ryan:      /* user sub-object */
}

So thatā€™s the basic users object. When we do the line

for (let name in users){ ...}

Weā€™re saying, ā€œfor each of the properties of the users object, take that property name and assign that, as a string value, to the variable name, then do this loop.ā€ So we are iterating over the list of users. There is no ā€œindex orderā€ enforcement, so we canā€™t count on Alan being first, but letā€™s pretend he is.

The first pass through our for...in loop, the string value Alan is assigned to the variable name. Within the scope of that for loop, name is the string ā€˜Alanā€™.

At each iteration, we get another direct child property of that users object, and assign the property name to our variable, and do the same loop.

Learn more about for...in on devDocs.

1 Like

Thank you very much. You are always a great help, and I truly appreciate it.

1 Like

Nah. Iā€™m just glad to have good questions to answer. Keep 'em coming!!

1 Like

hereā€¦ where? :laughing:

1 Like

Ooops. Forgot that link. Thanks for keeping me honest! rofl

All fixed, the link to the devdocs page is in there now. :wink: