question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Object Properties Private

See original GitHub issue

Challenge Name

Make Object Properties Private

Issue Description

I am not able to find a bug in this snippet.

Browser Information

  • Browser Name, Version:
  • Operating System:
  • Mobile, Desktop, or Tablet:

Your Code

 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 gear=0;
 
  this.setGear=function(set){
    return set;
  };
  this.getGear=function(){
    gear += set;
  };
};

var myCar = new Car();

var myBike = new Bike();

 
 

Screenshot

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robbawebbacommented, Jan 28, 2017

Hi @qkoots, thank you for your report. I’ll message you on gitter to explain the challenge a bit more. Please keep in mind that the GitHub issue tracker is for bugs only. If you need more help with the challenges, please use the chat rooms:

JavaScript help chat room Other Official Rooms

Thanks, and happy coding!

1reaction
raisedadeadcommented, Jan 5, 2017

Hi @debashispanda, as pointed by @robbawebba your code is incorrect.

Thanks for the report. The issue tracker is for reporting bugs only.

Please use the chat rooms:

or try looking through our forum for help with a specific challenge.

Happy Coding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Make Private Properties in JavaScript - Webtips
The private keyword in object-oriented languages is an access modifier that can be used to make properties and methods only accessible inside the...
Read more >
Is there a way to make private a javascript object property?
Use TypeScript and its private keyword. · Wait for JS enhancements for private fields, which may take the form #foo . · Use...
Read more >
How to create Private Properties in JavaScript.
By default, JavaScript allows you to read and modify all the properties. But by using the Proxy objects, you can create private properties...
Read more >
Private and protected properties and methods
In object-oriented programming, properties and methods are split into two groups: Internal interface – methods and properties, accessible from ...
Read more >
Private properties in JavaScript - Curiosity driven
Another approach to storing private properties involves WeakMaps. An instance of WeakMap is hidden inside a closure and indexed by Person instances. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found