ES6 - Prevent Object Mutation

Tell us what’s happening:
I’ve written the code properly however I’m getting an error

// running tests

PI

should equal

3.14

. // tests completed
// console output
ReferenceError: object is not defined

Your code so far
function freezeObj() {
const MATH_CONSTANTS = {
PI: 3.14
};
// Only change code below this line
object.freeze(freezeObj);
// Only change code above this line
try {
MATH_CONSTANTS.PI = 3.14;
} catch(ex) {
console.log(ex);
}
return MATH_CONSTANTS.PI;
}
const PI = freezeObj();

function freezeObj() {
  const MATH_CONSTANTS = {
    PI: 3.14
  };
  // Only change code below this line
    object.freeze(freezeObj);
  // Only change code above this line
  try {
    MATH_CONSTANTS.PI = 3.14;
  } 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/112.0.0.0 Safari/537.36

Challenge: ES6 - Prevent Object Mutation

Link to the challenge:

In this challenge you are going to use Object.freeze to prevent mathematical constants from changing.

Close, but the spelling needs to exactly match. object isn’t defined, but Object is!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.