# Day 1: Let and Const

# Day 1: Let and Const

Frankcarvajal + 2 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

mullapudieswar20 + 2 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

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.

Aminson_Jets + 0 comments Hay People, I need help! I have already writed my code and its doesnt works correct, here:

function main(area, perimeter) { readLine(radius); console.log() } function getArea(area, radius) { let area; area = 3.14 * (radius * radius); return area; } function getPerimeter(perimeter, radius) { let perimeter; perimeter = 2 * 3.14 * radius; return perimeter; } }

Can You explain my, who I made misstake.

daniel287 + 1 comment I understand and am able to solve the problem yet I don't know how to answer it for hackerrank!!!

`function main(r) { // Write your code here. Read input using 'readLine()' and print output using 'console.log()'. const PI = Math.PI; let area = PI * Math.pow(r, 2); let perimeter = PI * 2 * r; console.log(area); console.log(perimeter); // Print the area of the circle: // Print the perimeter of the circle: 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."); }`

}

daniel287 + 0 comments above returns "WRONG ANSWER" T_T

adisen + 0 comments Confused initially. Getting NaN. Guessed this is really a problem to learn the use of readLine.

function main() { const PI = Math.PI; let r = readLine(); let area = PI * Math.pow(r, 2); let perimeter = 2 * PI * r; console.log(area); console.log(perimeter);

Sort 41 Discussions, By:

Please Login in order to post a comment