Facing some strange error in the challenge Use Closure to Protect Properties Within an Object from Being Modified Externally

Hi, Everyone. Constantly getting this error:

// running test
Maximum call stack size exceeded
// tests completed

Can anyone help?

Your code so far


function Bird() {
  let weight = 15;

  this.getWeight = function(){
    return weight;
  };
}
  let ducky = new Bird();
  ducky.getWeight();



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally/

Hi,

You don’t need to include extra statements at bottom after defining your constructor. Also you don’t need a semicolon at the end of your getWeight function.

2 Likes