...

View Full Version : radius question



JohnBoy007_2006
06-21-2010, 11:38 AM
how can i create javascript so that the following methods produce the output listed next it.

circle = new Circle();
console.log(circle.get_area()); // 3.141592653589793
circle.set_radius(10);
console.log(circle.get_area()); // 314.1592653589793
console.log(circle); // the radius of my circle is 10 and it's area is 314.1592653589793

Philip M
06-21-2010, 11:56 AM
Homework again? Please read the forum rules.


<script type = "text/javascript">
var radius = 10;
var circumf = 2 * (Math.PI * radius);
alert (circumf);
var area = (Math.PI * radius * radius);
alert (area);
</script>


http://www.answerspice.com/c119/1511134/got-a-question-i-dont-understand-can-anyone-make-sense-of-it



"I am extraordinarily patient, provided I get my own way in the end". - Margaret Thatcher, British politician (1925 - )

Old Pedant
06-22-2010, 12:08 AM
Ummm...Philip...That is *JAVA* code he is showing there. console.log is for Java, not for JavaScript.

JohnBoy: You are in the WRONG FORUM! THis is the JavaScript forum.

There is little relationship between Java and JavaScript other than the first 4 characters of their names.

Dean440
06-22-2010, 12:50 AM
Ummm...Philip...That is *JAVA* code he is showing there. console.log is for Java, not for JavaScript.

JohnBoy: You are in the WRONG FORUM! THis is the JavaScript forum.

There is little relationship between Java and JavaScript other than the first 4 characters of their names.

console.log() can be used in JavaScript. It prints to the JavaScript/Developer/Firebug console.

Old Pedant
06-22-2010, 08:39 AM
Ahhh...did not know that, at all. I so seldom use Firebug for anything except debugging, and of course I wouldn't put console.log() into a normal web page.

I admit I was fooled by the new Circle() as well. Yes, I know you could create a Circle object in JS code, but I just assumed (shame on me) he was using Circle from one of the Java graphics libraries.

Okay...shut my mouth.

Old Pedant
06-22-2010, 08:42 AM
So if this really is JavaScript, then presumably all you need to do is


console.log( "the radius of my circle is " + circle.get_radius()
+ " and its area is " + circle.get_area() );

Or something similar to that.

Oh, and you do *NOT* use an apostrophe in "its" unless you are creating the contraction for "it is".

Philip M
06-22-2010, 08:48 AM
console.log() can be used in JavaScript. It prints to the JavaScript/Developer/Firebug console.

It is similar to alert.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum