Tell us what’s happening:
Describe your issue in detail here.
I need help with this challenge,
function freezeObj() {
const MATH_CONSTANTS = {
PI:3.14
};
// Only change code below this line
// Only change code above this line
try {
MATH_CONSTANTS.PI = 99;
} catch(ex) {
console.log(ex);
}
return MATH_CONSTANTS.PI;
}
const PI = freezeObj();
( You should not replace the const
keyword.
Passed
MATH_CONSTANTS
should be a constant variable (by using const
).
You should not change the original declaration of MATH_CONSTANTS
.
PI
should equal 3.14
.)
It is |ES6 Prevent Object Mutation, I’ve tried the given solution couldn’t go through, please it takes more than an hour!
thanks InAdvace !
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Prevent Object Mutation
Link to the challenge: