Day 1: Let and Const (10 Days of Javascript)

Task:

  1. Declare a constant variable,PI , and assign it the value Math.PI. You will not pass this challenge unless the variable is declared as a constant and named PI (uppercase).
  2. Read a number,r, denoting the radius of a circle from stdin.
  3. Use PI and r to calculate the area and perimeter of a circle having radius r.
  4. Print area as the first line of output and print perimeter as the second line of output.


Solution:

function main() {
    
    const PI=Math.PI;
     let r=readLine();
    
     console.log(PI*r*r);
    
     console.log(2*(PI+r));

    try {    
       
        PI = 0;
       
        console.log(PI);
    } catch(error) {
        console.error("You correctly declared 'PI' as a constant.");
    }
}

Leave a Reply