Day 1: Let and Const

Day 1: Let and Const

Objective

In this challenge, we practice declaring variables using the let and const keywords. Check out the attached tutorial for more details.

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 .
  4. Print area as the first line of output and print perimeter as the second line of output.

Input Format

A single integer, r, denoting the radius of a circle.

Constraints

  • 0 <= n <= 100
  • r is a floating-point number scaled to at most 3 decimal places.

Output Format

Print the following two lines:

  1. On the first line, print the area of the circle having radius r.
  2. On the second line, print the perimeter of the circle having radius r.

Sample Input 0

1
2.6

##Sample Output 0

1
2
21.237166338267002
16.336281798666924

Explanation

Given the radius r = 2.6, we calculate the following:

  • area = (pi*r^2)
  • perimeter = ({2}pir^2)

We then print area as our first line of output and perimeter as our second line of output.




Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function main() {
// Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
let r = parseFloat(readLine());
const PI = Math.PI;

// Print the area of the circle:
console.log(PI * r * r);

// Print the perimeter of the circle:
console.log(PI * 2 * r);

try {
// Attempt to redefine the value of constant variable PI
PI = 0;
// Attempt to print the value of PI
console.log(PI);
} catch (error) {
console.error("You correctly declared 'PI' as a constant.");
}
}

Buy Me A Coffee

Comments

10Days of JS 30Days of Code Algorithm Android Debug Bridge Android Debugging Basic for Web Blog Browsers Chrome으로 Android Debugging 방법 Correctness and the Loop Invariant hackerrank solution in javascript Debug Tools Development Environment in MacOS ES6 Front-End Funny String of Algorithms hackerrank solution in javascript Funny String of Algorithms hackerrank solution in typescript Generator Github Page with Hexo Github Pages HackerRank HackerRank in a String of Algorithms hackerrank solution in javascript HackerRank in a String of Algorithms hackerrank solution in typescript Hexo Hexo Icarus theme Hexo 블로그 만들기 Hexo+Github How Browsers work Insertion Sort - Part 1 hackerrank solution in javascript Insertion Sort - Part 2 hackerrank solution in javascript JS Library JavaScript Level1 Level2 Loops MacOS 개발 환경 설정하기 Mobile web Debugging Node.js Pangrams of Algorithms hackerrank solution in javascript Pangrams of Algorithms hackerrank solution in typescript Problem Solving Programmers Quicksort 1 - Partition hackerrank solution in javascript React RoadMap Running Time of Algorithms hackerrank solution in javascript Safari Debugging Safari Technology Preview Settings Sorting String Strings Strong Password of Algorithms hackerrank solution in javascript TypeScript blog iPhone Safari Debugging 방법 insertion sort 모바일 웹 디버깅 아이폰 사파리를 디버깅하는 방법 안드로이드 디버그 브리지 안드로이드 디버깅하는 방법
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×