-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDay1.LetAndConst.js
69 lines (49 loc) · 1.81 KB
/
Day1.LetAndConst.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Objective
// In this challenge, we practice declaring variables using the let and const keywords. Check out the attached tutorial for more details.
// Task
// Declare a constant variable, , 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).
// Read a number, , denoting the radius of a circle from stdin.
// Use and to calculate the and of a circle having radius .
// Print as the first line of output and print as the second line of output.
// Input Format
// A single integer, , denoting the radius of a circle.
// Constraints
// is a floating-point number scaled to at most decimal places.
// Output Format
// Print the following two lines:
// On the first line, print the of the circle having radius .
// On the second line, print the of the circle having radius .
// Sample Input 0
// 2.6
// Sample Output 0
// 21.237166338267002
// 16.336281798666924
// Explanation 0
// Given the radius , we calculate the following:
// We then print as our first line of output and as our second line of output.
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
// Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
const PI = Math.PI;
let r = readLine('r');
// Print the area of the circle:
console.log(Math.pow(r, 2) * PI);
// Print the perimeter of the circle:
console.log(2 * PI * r);
}