Page 205 - Web_Application_v2.0_C12_Fb
P. 205

document.getElementById("d").innerHTML ="Hello! you are " + age +" years old.";
                    }};

                    </SCRIPT>
                    </HEAD>
                    <BODY style="text-align: center;">
                    <H1 style="color:blue;"> Using the Prompt Box in JavaScript </H1>
                    <INPUT type="button" onclick="func1()" value="Click me!">

                    <P id="d"></P>
                    </BODY>
                    </HTML>
                 Output:














                  When Click me! button is clicked, it displays:         When OK button is clicked, it displays:
















                 User-defined Function

                 A user-defined function in JavaScript is a function that is created to perform a specific task or set of tasks. These
                 functions allow you to encapsulate reusable code that can be called multiple times within your program, making
                 it modular, readable, and easier to maintain.
                 A user-defined function typically has the following components:
                   Function Declaration: The keyword function is used to declare a function.

                   Function Name: This is the identifier used to call the function.
                   Parameters (optional): These are the values you pass into the function when calling it. These values are
                    used inside the function to perform operations.
                   Function Body: This is the block of code that defines the functionality of the function.

                   Return Statement (optional): The return statement sends a value back to the caller.
                 The syntax to create a user-defined function is as follows:

                    function functionName(parameter1, parameter2, ...) {

                    // Code to be executed
                                                                                                  JavaScript Part 2  203
   200   201   202   203   204   205   206   207   208   209   210