Java Script Lesson 6 - Functions With Two Arguments

In our last lesson, we learned how to use JavaScript functions to return a specified result once an action was performed. In this lesson, we will learn how to use JavaScript with arguments to return an answer to an equation. You can copy and paste this code into your page as you learn, and modify it as needed.

Let’s start with our code. Keep in mind our last lesson on functions as you go through this code. Functions are used to return an answer to an equation or to perform simple tasks as we have previously illustrated.

lesson 6

In our script above, we start off with listing the function. In this case, we want the total of NumberA and NumberB, so we type in total. The next step is to program the script to return the correct value. In this case, we want NumberA and NumberB added together.

The first part of the script ends and then you begin Phase 2. Using the document.write tag, you then program the script with what the values for NumberA and NumberB are. This will allow the first phase of the script to return the answer.

Once you have saved this file and uploaded it to your server, this is what you should see on your HTML page:

28

You are using this script to call a function that contains two arguments.

The function will return the sum of these two arguments.

If you see the above on your page, congratulations! You have just written your first JavaScript containing a function with two arguments, and the result of these two arguments.

You can modify the above code to use subtraction, or other values to suit your page.

This is a very basic example of how to use JavaScript to call a function containing arguments. You can start by pasting this code right into your page and then modifying it as needed. Once you have your syntax correct, and you are within the correct parameters, you can use this script in a variety of ways.

Our next lesson will cover how to create your own JavaScript clock.

Related Posts:
Java Script Lesson 4 - Functions
Java Script Lesson 5 - More Functions
Java Script Lesson 3 - Arrays
Java Script Lesson 8 ‘ Using More Than One JavaScript on a Page
PHP Lesson 5 - PHP Functions

Posted on 12/27/05 1:50 AM

Be the first to comment!

Leave a Reply


SYNDICATION

    NEW! Blog Feed:
    Reviews Feed:
    News Feed:
    Resources Feed: