# Make Object Properties Private, NO CLUE WHAT TO DO

**URL:** <https://forum.freecodecamp.org/t/make-object-properties-private-no-clue-what-to-do/157369>\
**Category:** General\
**Created:** [November 4, 2017, 8:48pm UTC](https://forum.freecodecamp.org/t/make-object-properties-private-no-clue-what-to-do/157369 "2017-11-04T20:48:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sypher85](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sypher85/32/61632_2.png) [@sypher85](https://forum.freecodecamp.org/u/sypher85)\
**Post date:** [November 4, 2017, 8:48pm UTC](https://forum.freecodecamp.org/t/make-object-properties-private-no-clue-what-to-do/157369/1 "2017-11-04T20:48:08Z")

</div>

**Tell us what’s happening:**  
I just have no clue what to do here, I dont even understand it.

**Your code so far**

```auto
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.

};

var myCar = new Car();

var myBike = new Bike();

```

**Your browser information:**

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36`.

**Link to the challenge:**  
[https://www.freecodecamp.org/challenges/make-object-properties-private](https://www.freecodecamp.org/challenges/make-object-properties-private)

---

<div class="post-metadata">

**Author:** ![alecaceaes](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alecaceaes/32/160822_2.png) [@alecaceaes](https://forum.freecodecamp.org/u/alecaceaes)\
**Post date:** [November 6, 2017, 9:23am UTC](https://forum.freecodecamp.org/t/make-object-properties-private-no-clue-what-to-do/157369/2 "2017-11-06T09:23:28Z")

</div>

Use the **this** keyword to create public properties and methods of the current objects.

But, when You need to create private ones (not accessible from the outside of the object)instead of using the keyword **this** declare it with **var** so that it is private outside its scope.

Also try searching google esp the one’s from stackoverflow, check this article [https://stackoverflow.com/questions/33908028/public-vs-private-properties-inside-constructors](https://stackoverflow.com/questions/33908028/public-vs-private-properties-inside-constructors), and reading the comments they can be helpful sometimes.

```auto
var Car = function() {
  // this is a private variable -- USES VAR KEYWORD FOR PRIVATE
  var speed = 10;

  // these are public methods -- USES THIS KEYWORD FOR PUBLIC
  this.accelerate = function(change) {
    speed += change;
  };
};

```

---

<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:** [January 17, 2021, 8:35pm UTC](https://forum.freecodecamp.org/t/make-object-properties-private-no-clue-what-to-do/157369/3 "2021-01-17T20:35:27Z")

</div>

Closed on January 17, 2021, 8:35pm UTC


