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
13 Réponses
+ 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
+ 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)
+ 2
Put this two lines of your code into function calcCirc
+ 2
Yeeesss! Good job! 😁👍💪🎉
have you figured out how and why it works? can you explain?
+ 1
Good! And now in the output location (//the output), delete console.log and simply call the function with the parameter r.
+ 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!
}
+ 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!
+ 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))
}
+ 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
}
0
the console.log code is provided
isn't r already defined?
//complete the function
function calcCirc(r){
2*Math.PI * r
0
var cir1= 2*Math.PI*r
console.log (cir1.toFixed(2))
The result says cir1is not defined.
0
//complete the function
function calcCirc(r){
var cir1= 2*Math.PI*r
console.log (cir1.toFixed(2))
0
still missing something 😕