0

Circumference of a circle in Javascript

The result shows r as undefined. The formula is 2*PI*r function main() { var r = parseInt(readLine(), 10) //the output console.log(calcCirc(r).toFixed(2)); } //complete the function function calcCirc(){ 2*Math.PI * r

15th Apr 2021, 10:51 AM
Lee 4 Code
Lee 4 Code - avatar
13 Respostas
+ 2
Hi! 1. in the output location (//the output), delete console.log and simply call the function with the parameter r. 2. in the function itself, assign any one variable to calculate the value. in the next line, output this variable to the console and apply the method to it .toFixed(2) Edit: in the parentheses of the function, also insert the r parameter
15th Apr 2021, 11:30 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
I didn't understand your question very well, but I did it differently and I completed all five tests. so, in this piece of code (function) that you showed. add a variable to it and assign a formula to it. because right now, this formula is just hanging in the air. there's no way you can use it. in the next line, output this variable to the console along with the property .toFixed(2)
15th Apr 2021, 1:00 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Put this two lines of your code into function calcCirc
15th Apr 2021, 1:50 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Yeeesss! Good job! 😁👍đŸ’Ș🎉 have you figured out how and why it works? can you explain?
16th Apr 2021, 11:53 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Good! And now in the output location (//the output), delete console.log and simply call the function with the parameter r.
15th Apr 2021, 10:22 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thank you Yaroslav-Vernigora! function main() { var r = parseInt(readLine(), 10) //the output calcCirc(r); } //complete the function function calcCirc(r){ var cir1= 2*Math.PI*r console.log (cir1.toFixed(2)) Success! }
16th Apr 2021, 11:10 AM
Lee 4 Code
Lee 4 Code - avatar
+ 1
I was just reviewing the code and associating the changes with the meaning of the actions. at //the output calcCirc(r) defines r... the formula had to be designated to a variable, thus allowing it to be called and affixed with the rounding method .toFixed while being outputed to the console. more study and chatter clears the fog of coding Thank you!
16th Apr 2021, 12:00 PM
Lee 4 Code
Lee 4 Code - avatar
+ 1
function main() { var r = parseInt(readLine(), 10) //the output calcCirc(r); } //complete the function function calcCirc(r){ var cir1= 2*Math.PI*r console.log (cir1.toFixed(2)) }
30th May 2021, 4:20 PM
Sakshi Wadhwa
+ 1
function main() { var r = parseInt(readLine(), 10) //the output console.log(calcCirc(r).toFixed(2)); } //complete the function function calcCirc(radius){ // i put radius in calcCirc because it should be a parameter to avoid get an error var totoal =2*Math.PI*aradius return totoal }
12th Sep 2021, 6:14 AM
Saleh Alsadi
0
the console.log code is provided isn't r already defined? //complete the function function calcCirc(r){ 2*Math.PI * r
15th Apr 2021, 12:14 PM
Lee 4 Code
Lee 4 Code - avatar
0
var cir1= 2*Math.PI*r console.log (cir1.toFixed(2)) The result says cir1is not defined.
15th Apr 2021, 1:19 PM
Lee 4 Code
Lee 4 Code - avatar
0
//complete the function function calcCirc(r){ var cir1= 2*Math.PI*r console.log (cir1.toFixed(2))
15th Apr 2021, 1:58 PM
Lee 4 Code
Lee 4 Code - avatar
0
still missing something 😕
15th Apr 2021, 1:59 PM
Lee 4 Code
Lee 4 Code - avatar