freeCodeCamp icon indicating copy to clipboard operation
freeCodeCamp copied to clipboard

challenge passes a sample test (myBike.gear should remain undefined)

Open tommygebru opened this issue 10 years ago • 5 comments

Challenge Make Object Properties Private has an issue. User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My 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 = 4;


this.getGear = function(){
    return gear;
};
this.setGear = function(change){
    return gear;
};



};

var myCar = new Car();

var myBike = new Bike();

tommygebru avatar Jan 17 '16 04:01 tommygebru

What is supposed to be the issue here? Your code looks correct and it passes. Do you believe it should not?

SaintPeter avatar Jan 17 '16 05:01 SaintPeter

@SaintPeter Their setGear method isn't actually modifying the variable, they're just setting it to the number the test is expecting so it passes.

arialaurel avatar Jan 17 '16 19:01 arialaurel

Oh my I have not used my email in soooo long ! Hey Rex, Logan is right some coders are having a difficult time passing the challenge and copy +pasting the "loophole" on gitter..... before others have a chance to really comprehend the challenge!

On Sun, Jan 17, 2016 at 11:57 AM, Logan Tegman [email protected] wrote:

@SaintPeter https://github.com/SaintPeter Their setGear method isn't actually modifying the variable, they're just setting it to the number the test is expecting so it passes.

— Reply to this email directly or view it on GitHub https://github.com/FreeCodeCamp/FreeCodeCamp/issues/6241#issuecomment-172371757 .

tommygebru avatar Jan 18 '16 16:01 tommygebru

It sounds like we need several other setGear/getGear checks for values other that 4.

SaintPeter avatar Jan 18 '16 16:01 SaintPeter

@tommygebru Your setGear function is wrong. It should accept the gear value and assign it to the gear variable and getGear fn will return the value.

jestintab avatar Feb 02 '16 06:02 jestintab