Need Help with Object Oriented Programming - Help!

Need Help with Object Oriented Programming - Help!


Hi guys!
This is my first post on the freecodecamp Forum. I seek help regarding the topic “Make Object Properties Private”. Here is the code which is pre-written :

var Car = function() {
var speed = 10;
this.accelerate = function(change) {
speed += change;
this.decelerate = function() {
speed -= 5;
this.getSpeed = function() {
return speed;
var Bike = function() {
var myCar = new Car();
var myBike = new Bike();

Over Here, in the accelerate property, you have a parameter called change. How will you call that? How will you put value in the change parameter? because when you will call the variable car, you wont be able to put any value in it as parameter because the function called “function” doesn’t itself have any predefined “enter-able” parameter…


Hey @srujanmhase,

You’re working on:

Let’s see if I can help you a little with this…

First, Car is a class.

When you create an instance of a class,

then you have a a variable named “car”, that is of type “Car”.

The Car class has a few functions; one of them is named “accelerate”. Car’s accelerate() function accepts one parameter, which is named “change”.

To call the function on your instance of Car, you would do this:

If you change Car’s definition of accelerate() to the following, you’ll see a pop-up dialog that contains a message:

this.accelerate = function(change) { speed += change; alert("speed: " + speed + ", change: " + change); };


Wow! Thank you @jmontreal sir! I understood it!