Skip to Content

10 days Javascript: Let and Const

Posted on One min read

Day 1: Let and Const

Solution for:


  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 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.

function main() {
  // Write your code here. Read input using 'readLine()'
  // Print output using 'console.log()'.
  const PI = Math.PI;

  const r = readLine();

  // Print the area of the circle:
  var area = PI * (r * r);

  // Print the perimeter of the circle:
  var perimeter = 2 * PI * r;