It says that PI equals 3.14 but its still an error? why?

Tell us what’s happening:

Your code so far


function freezeObj() {
  "use strict";
  const MATH_CONSTANTS = {
    PI: 3.14
  };
  // change code below this line
Object.freeze(PI);


  // change code above this line
  try {
    MATH_CONSTANTS.PI = 99;
  } catch( ex ) {
    console.log(ex);
  }
  return MATH_CONSTANTS.PI;
}
const PI = freezeObj();

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/prevent-object-mutation** **

but PI is not the object. it is an attribute on an object. Thus, you can’t actually freeze PI (though my gran used to freeze pie all the time).

1 Like

PI isn’t object. It’s a property of a object called MATH_CONSTANTS. In order to freeze object from mutations you need to pass an object not its properties. So it should be Object.freeze(MATH_CONSTANTS);