freeCodeCamp Algorithm Challenge Template Guide

freeCodeCamp Algorithm Challenge Template Guide
0

#1

freeCodeCamp Algorithm Challenge Template Guide

Algorithm [Steamroller]
:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: 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()
:speech_balloon: 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();

:rocket: Run Code

Code Explanation:
It should work at the first place.

:clipboard: NOTES FOR CONTRIBUTIONS:
:warning: 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. :traffic_light:
Please add your username only if you have added any relevant main contents. (:warning: DO NOT remove any existing usernames)
See :point_right: Wiki Challenge Solution Template for reference.


#2

#3

#4