Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: radius question

  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    radius question

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Homework again? Please read the forum rules.

    Code:
    <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/1511...ke-sense-of-it



    "I am extraordinarily patient, provided I get my own way in the end". - Margaret Thatcher, British politician (1925 - )
    Last edited by Philip M; 06-21-2010 at 04:29 PM.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by Old Pedant View Post
    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.
    Last edited by Dean440; 06-21-2010 at 11:55 PM.

  • Users who have thanked Dean440 for this post:

    Old Pedant (06-22-2010)

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    So if this really is JavaScript, then presumably all you need to do is
    Code:
    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".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Quote Originally Posted by Dean440 View Post
    console.log() can be used in JavaScript. It prints to the JavaScript/Developer/Firebug console.
    It is similar to alert.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •