SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Operations

    Hello,

    I'm trying to perform simple javascript functions. I want to execute the following operations: addition, subtraction, multiply, division, and a even odd function.

    So far I did the addition. Its not working and I was wondering if someone can offer help. Here's what I have so far.

    My HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>

    <head>

    <title> </title>


    <script src="ron3.js" type="text/javascript"></script>
    <link href="ron3.css" type="text.css" rel="stylesheet"/>

    </head>

    <body>
    <script src="ron3.js" type="text/javascript">
    document.writeln(add(10,2));
    </script>





    </body>

    </html>

    And then my external js file:

    function add(num1+num2)

    {
    return num1 + num2;
    }

    In the book I'm reading, it shows me how to get the area of a rectangle by using: function CalcArea
    var area (length* width);
    return area;
    I was thinking that instead of the function name add for addition I should use CalcSum. If anyone can direct me to a site that lists the function names for the operations I mention above, that would be great. My book seems to only cover area and leave the rest up to me.

    Thanks

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    function add(num1, num2){
    return num1+num2;
    }

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks mrhoo. But does my html look right. I think that's my problem a syntax error in the html.

    thanks

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <script src="ron3.js" type="text/javascript">
    document.writeln(add(10,2));
    </script>

    No script between the script tags is interpreted when a src is specified.
    You need another set of script tags, or put all the code in the remote file,
    or the whole script in the html.

    <script src="ron3.js" type="text/javascript">
    </script>

    <script type="text/javascript">
    document.writeln(add(10,2));
    </script>

  5. #5
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mrhoo. I got it to work.


Bookmarks

Posting Permissions

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