Use Closure to Protect Properties Within an Object from Being Modified Externally

Use Closure to Protect Properties Within an Object from Being Modified Externally
0.0 0

#1

Tell us what’s happening:
Hi, not sure what is wrong here. I tested on inspection and the get method is the correct output when i tested, a private variable and a getmethod yet my 2nd test is wrong
Your code so far


function Bird() {
  let weight = 10;

  this.getWeight = function(){
    return weight;
  };

}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 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


#2

Hi @Balancedsan,

Your code is right, but you should change the value of weight to 15 like this let weight = 15;

Hope this help you to solve example, good luck my friend.

Regards,
Ali Mosaad


#3

thank you very much it works :), weirdly it dosent state anywhere to change weight to 15


#4

Hi @Balancedsan,

Good luck and have a happy coding, don’t miss small things again :wink:

Regards,
Ali Mosaad