# Day 1: Let and Const

# Day 1: Let and Const

Frankcarvajal + 3 comments Anyone else think this is the worst possible test indication of understanding Let and Const and that the challenge here is understanding readLine()? Ha

mvasigh + 0 comments It's just really poorly written! Had me questioning my sanity for a moment.

ceyler + 0 comments Agreed... Sadly, this seems to be a trend in on this platform.

2016quezadaj + 0 comments Same here! This readLine() is proving to be the real challenge.

mullapudieswar20 + 3 comments function main() {

`let r = 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);`

mullapudieswar20 + 0 comments **It works**azmikhairul18 + 0 comments thanks

aiswarya110498 + 0 comments This code really works.. Thank you..

vamshi_reddy0896 + 2 comments why is my code printing: 0

saurabhsingh8362 + 0 comments cant see your code clearly

manand881 + 0 comments you probably declared pi as a variable. check try catch block

jhggins + 5 comments I'm curious as to why r**2 causes a runtime error

solution.js:29 console.log(PI*(r**2)); ^ SyntaxError: Unexpected token *

edgars_fjodorovs + 0 comments Same here. Tested in console, everything works. I uses

r*r

jjennings239 + 0 comments It has to do with the javascript environment hackerrank is running which is node.js v6.9.1. The exponentiation operator(**) is only partially supported for this version. If it isn't supported an unexpected token * error is thrown.

[deleted] + 0 comments As @jjennings239 wrote, exponentiation operator(**) is not supported in all environments. You can try to use Math.pow(a,b) function. In your case it would be:

console.log(PI*Math.pow(r,2));

pnaga_pavan2015 + 0 comments you cannot perfom r square with that command use r^2 instead of that .It will work for sure.

saurabhsingh8362 + 0 comments why you write **

_clfm_ + 0 comments ## Clean & correct

The challenge is called "Let and Const", but there's really no reason not to use

`const`

for both variables here. Let me know if you have any questions!function main() { const PI = Math.PI; const r = parseFloat(readLine()); console.log(PI * (r ** 2)); console.log(2 * PI * r);

(From my HackerRank repo on GitHub.)

aslamudheentk9 + 2 comments MY CODE let PI = Math.PI; let r =readLine();

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

MY OUTPUT 21.237166338267002 16.336281798666924 0

is it me or hackerrank

skylfw + 0 comments You have to declare PI as a const to get rid of the additional 0.

saurabhsingh8362 + 0 comments this is expected output

tilper + 0 comments Typo in that error message about PI? Incorrectly, not correctly.

honestyrules26 + 0 comments cant we do r^2

danielgomesp + 0 comments Tip: Use the function

**Math.pow()**to figure out the value of x^y.

iam38 + 0 comments This works lol

function main() { // Write your code here. Read input using 'readLine()' and print output using 'console.log()'. const PI = Math.PI; let radius = readLine(); let area = PI * (Math.pow(radius, 2)); let perimeter = 2 * PI * radius; // Print the area of the circle: console.log(area); // Print the perimeter of the circle: console.log(perimeter); try {

Sort 45 Discussions, By:

Please Login in order to post a comment