Prevent Object Mutation1

Prevent Object Mutation1
0

#1

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


#2

the example code give you the correct syntax for freezing:

Object.freeze(obj);

do you see what your code is missing?


#3

I don’t understand what is missing.


#4

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

Object.freeze(obj);

Just look at them to see what is wrong.


#5

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


#6

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 .


#7

And how can I do it?


#8

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


#9

Yes I got it thank you for help