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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    81
    Thanks
    45
    Thanked 0 Times in 0 Posts

    Why's this object not working(Javascript)

    box=new Object();
    box.height=30;
    box.length=20;

    box.both=function(box.height,box.length){
    return box.height*box.length;
    }

    document.write(box.both(10,20));

    Well as the title says.

    First off I'd created an object.
    Made to properties, height and length.
    Assigned a value to each.
    Made a method BOTH
    In function I'd put 2 arguments which are object properties.
    Returned their product.
    And finally called the function giving it numerical value..



    Why's this not working

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta charset="UTF-8">
    </head>
    <body>

    <script>
    box=new Object();
    box.height=30;
    box.length=20;
    box.both=function(h,l){
    if(h*l){
    this.height=h;
    this.length=l;
    }
    return this.height*this.length;
    }
    document.write(box.both(),"<br>");
    document.write(box.both(40,25));
    </script>

    </body>
    </html>
    Last edited by DaveyErwin; 10-24-2013 at 03:35 AM.


  •  

    Posting Permissions

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