-
Notifications
You must be signed in to change notification settings - Fork 3
/
17 Functions.html
38 lines (31 loc) · 1.33 KB
/
17 Functions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<html lang="en">
<head><title>Functions</title>
<!--
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().
Functions also help in keeping the code more updatable and more organise
Why to use Functions?
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
-->
</head>
<body>
<script type="text/javascript">
//defining the function
function display(){
alert("Function Called");
}
display(); // calling the function // here when you open the webpage its going to call it
//finding average of two numbers
//average formulla (x+y)/2
function average(a,b){
return ((a+b)/2); // or return (a+b)/2;
}
var x=4;
var y=5;
//calling the average function
document.write(average(x,y)); // also displaying the return value of function and calling it also
</script>
</body>
</html>