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

COMPUTER SOFTWARE APPLICATION - CITS
























           II. Function with parameters
              1. Open the text editor
              2. Write the following codes
                 <html >
                 <head>
                 <title> Function with parameters </title>
                 </head>
                 <body>
                 <script>
                 // Defining a function named “greet” that takes a parameter named “name”
                 function greet(name)
                 {
                 // Inside the function, logging a greeting message to the console with the provided name
                 console.log(“Hello, “ + name + “!”);
                 }
                 // Calling the function with an argument “John”
                 greet(“John”); // Output: Hello, John!

                 </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.























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