Tell us what’s happening:
In this challenge you are going to use Object.freeze to prevent mathematical constants from changing. However, adding Object.freeze results in [TypeError: “PI” is read-only]. The current working solution is simply click “Run the Tests” with zero edits.
**Your code so far**
function freezeObj() {
const MATH_CONSTANTS = {
PI: 3.14
};
// Only change code below this line
Object.freeze(MATH_CONSTANTS);
// Only 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 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0
If you do this, you will not pass all tests for the challenge. You need to add the freeze.
Here, this says to try to change MATH_CONSTANTS and print out the error message if changing the value of PI was successfully prevented. Seeing a message that PI was not changed is a good thing.
I think I get it. Because you put it in a try/catch, it looks like I’m getting an error. If this is true, this must cause a lot of confusion since the output changes immediately.