Page 163 - Computer Software Application TP - Volume 1
P. 163

COMPUTER SOFTWARE APPLICATION - CITS




           III. Function with return statement

              1  Open the text editor
              2  Write the following codes
                 <html >
                 <head>
                 <title> Function with return statement </title>

                 </head>
                 <body>
                 <script>
                 // JavaScript function with a return statement
                 function multiply(num1, num2) {

                 return num1 * num2;
                 }
                 // Example of using the function
                 var result = multiply(5, 3);

                 console.log(“Result of multiplication: “ + result);
                 </script> </script>
                 </body>
                 </html>
              3  Save the program as a .html file
              4  Open the html file with a web browser

              5  Go to the browsers console tab and verify the output.

















           TASK 2:  Creating Anonymous Functions
           I. Using Function Expression
              1  Open the text editor

              2  Write the following codes
                 <html >
                 <head>
                 <title> </title>
                 </head>

                 <body>



                                                           148
                               CITS : IT & ITES - Computer Software Application - Exercise 41
   158   159   160   161   162   163   164   165   166   167   168