Page 161 - Computer Software Application TP - Volume 1
P. 161
COMPUTER SOFTWARE APPLICATION - CITS
EXERCISE 41 : Creating and using Functions
Objectives
At the end of this exercise you shall be able to
• create user defined functions
• create Anonymus functions
Requirements
Tools/Materials
• Desktop / Laptop with latest configuration
• Text editor
• Web browser
Procedure
TASK 1: Creating a Function
I Function without parameters
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Function without parameters </title>
</head>
<body>
<script>
// Defining a function named “greet” without any parameters
function greet()
{
// Inside the function, logging a greeting message to the console
console.log(“Hello, world!”);
}
// Calling the function
greet(); // Output: Hello, world!
</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.
146