Tell us what’s happening:
The final requirement isn’t cleared despite PI being 3.14. The default code is enough to show this via console logging.
The solution is to use “Object.freeze(MATH_CONSTANTS);” in the provided space, but doing something like “MATH_CONSTANTS = Object.freeze(MATH_CONSTANTS);” won’t work.
Your code so far
function freezeObj() {
"use strict";
const MATH_CONSTANTS = {
PI: 3.14
};
// change code below this line
MATH_CONSTANTS = Object.freeze(MATH_CONSTANTS);
// 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; rv:61.0) Gecko/20100101 Firefox/61.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/prevent-object-mutation/