Prevent Object Mutation1

Tell us what’s happening:

What is wrong;

Your code so far


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

  // 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 10.0; 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/es6/prevent-object-mutation

the example code give you the correct syntax for freezing:

Object.freeze(obj);

do you see what your code is missing?

I don’t understand what is missing.

the above is your code. Below is the example provided to you:

Object.freeze(obj);

Just look at them to see what is wrong.

Miss (Obj).Right?
But I write that code:
function freezeObj() {
“use strict”;
const MATH_CONSTANTS = {
PI: 3.14
};
// change code below this line
Object.freeze(obj);

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

But tell me:
obj is not defined
obj is not defined
obj is not defined
obj is not defined

ok so the “obj” is not defined. That tells you that you are freezing something that doesn’t exist.

Refer back to the instructions for more help. I’ve pasted them here for you for convenience.

In this challenge you are going to use Object.freeze to prevent mathematical constants from changing. You need to freeze the MATH_CONSTANTS object so that no one is able alter the value of PI, add, or delete properties .

And how can I do it?

The instructions say: “freeze the MATH_CONSTANTS object”.
So just replace ‘obj’ with that.

Yes I got it thank you for help