freeCodeCamp Algorithm Challenge Template Guide

Algorithm [Steamroller]

Remember to use Read-Search-Ask if you get stuck. Try to pair program and write your own code

Problem Explanation:

In this challenge you are going to use Object.freeze to prevent mathematical constants from changing. You need to freeze the MATH_CONSTANTS object so that no one is able alter the value of PI, add, or delete properties .

Relevant Links

Object.freeze()

Hint: 1

If you already tried to freeze the constant and it didn’t work

try to assign it to a let variable and freeze that one.

try to solve the problem now

Spoiler Alert!

687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

Solution ahead!

```
function freezeObj() {
"use strict";
const MATH_CONSTANTS = {
PI: 3.14
};
// change code below this line
let mc = MATH_CONSTANTS;
Object.freeze(mc);
// change code above this line
try {
MATH_CONSTANTS.PI = 99;
} catch( ex ) {
console.log(ex);
}
return MATH_CONSTANTS.PI;
}
const PI = freezeObj();
```

Run Code

Code Explanation:

It should work at the first place.

NOTES FOR CONTRIBUTIONS:

DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.

Add an explanation of your solution.

Categorize the solution in one of the following categories — Basic, Intermediate and Advanced.

Please add your username only if you have added any relevant main contents. ( DO NOT remove any existing usernames)

See Wiki Challenge Solution Template for reference.