# Is it right that I am using variable as x.online?

**URL:** <https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [October 3, 2018, 1:58pm UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321 "2018-10-03T13:58:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roma1](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Roma1](https://forum.freecodecamp.org/u/Roma1)\
**Post date:** [October 3, 2018, 1:58pm UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321/1 "2018-10-03T13:58:29Z")

</div>

**Tell us what’s happening:**

Is it right that I am using variable as x.online? Why I can`t sove this task?

**Your code so far**

```js

let users = {
  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 result = 0;
      for(let x in obj){
        if(x.online == true){
          result+=1;
        }
      }
  return result;
  // change code above this line
}

console.log(countOnline(users));

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36`.

**Link to the challenge:**  
[https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/-iterate-through-the-keys-of-an-object-with-a-for---in-statement)

---

<div class="post-metadata">

**Author:** ![vipatron](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vipatron/32/81984_2.png) [@vipatron](https://forum.freecodecamp.org/u/vipatron)\
**Post date:** [October 3, 2018, 2:12pm UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321/2 "2018-10-03T14:12:37Z")

</div>

[Check out this fiddle and see what the problem in your code is](http://jsfiddle.net/sqakjeom/) (It isn’t what you titled this post. `x.online` is the correct way to access the data.

Also, check this out:

> **[Truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy)**
>
> In JavaScript, a truthy value is a value that is considered  true when encountered in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, "", null, undefined, and NaN).

---

<div class="post-metadata">

**Author:** ![vipatron](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vipatron/32/81984_2.png) [@vipatron](https://forum.freecodecamp.org/u/vipatron)\
**Post date:** [October 3, 2018, 2:14pm UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321/3 "2018-10-03T14:14:51Z")

</div>

Updated fiddle, if you aren’t comfortable with the console yet (you should get really comfortable with it, but hey, I am a completionist):

[http://jsfiddle.net/sqakjeom/1/](http://jsfiddle.net/sqakjeom/1/)

---

<div class="post-metadata">

**Author:** ![Roma1](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Roma1](https://forum.freecodecamp.org/u/Roma1)\
**Post date:** [October 4, 2018, 1:51am UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321/4 "2018-10-04T01:51:01Z")

</div>

Do you mean that I can use like this **if(x.online)**?

---

<div class="post-metadata">

**Author:** ![vipatron](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vipatron/32/81984_2.png) [@vipatron](https://forum.freecodecamp.org/u/vipatron)\
**Post date:** [October 4, 2018, 3:46pm UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321/6 "2018-10-04T15:46:41Z")

</div>

Sorry, @camperextraordinaire is correct. I noticed a different error and focused on that instead of addressing your object of objects. You should take his hint about how to access the relevant member.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 2, 2021, 11:28am UTC](https://forum.freecodecamp.org/t/is-it-right-that-i-am-using-variable-as-x-online/231321/7 "2021-02-02T11:28:48Z")

</div>

Closed on February 2, 2021, 11:28am UTC


