Prevent Object Mutation help

Tell us what’s happening:
As I’m doing all try and even using chrome as browser this showing an error always.
I really don’t know what’s the problem in the code.

Your code so far


function freezeObj() {
"use strict";
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 (Linux; Android 7.1.1; CPH1729) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36.

Challenge: Prevent Object Mutation

Link to the challenge:

There’s no problem in your code your browser does. What OS are you using?

My OS is Android Linux 7.1.1

This is the first code did you run on that OS? If it is then that OS might not be supported by Google anymore.

No but all the codes run properly. I don’t know what’s problem here!

Try this code

function freezeObj() {
  'use strict';
  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 = 99;
  } catch(ex) {
    console.log(ex);
  }
  return MATH_CONSTANTS.PI;
}
const PI = freezeObj();

Not working your code.

You tried to redefine a mathematical constant ‘Pi’ on line 10. Pi is a read-only property build into JavaScript.

Can you please tell me?

Hey there @utkarshmeshram0211 :wave:,

Your code should’ve worked fine, but it is because you messed with the setup code that made the test failed.

It’s probably best to press the Reset All Code and just wre-write the code you only needed which is Object.freeze(MATH_CONSTANTS);.

When the challenge says Only change code above/below this line it meant it, if you change it, it can cause it to fail. Next time, please write your code where you are told to…

Hope this helps :slight_smile:

Thank you that helped me, I will remember this in future.

1 Like

Glad I can help :slight_smile:. Just remember to always read and follow the directions :slight_smile:

Yes! Thanks for help😇