0% found this document useful (0 votes)
511 views

Css Practical 4

The document discusses JavaScript functions, including how to define a function using the function keyword, how functions can take parameters and return values, and provides examples of calling functions both with and without parameters. It also demonstrates how to call one function from another using an example program that defines two functions, one that calls the other while passing arguments.

Uploaded by

Shekhar Jadhav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
511 views

Css Practical 4

The document discusses JavaScript functions, including how to define a function using the function keyword, how functions can take parameters and return values, and provides examples of calling functions both with and without parameters. It also demonstrates how to call one function from another using an example program that defines two functions, one that calls the other while passing arguments.

Uploaded by

Shekhar Jadhav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER ENGINEERING DEPARTMENT

Subject: Client Side Scripting Subject Code: 22519


Semester: 5th Course: Computer Engineering
Laboratory No: L001B Name of Subject Teacher: Pokharkar M.S.
Name of Student: Roll Id: 17202C0009

Experiment No: 4
Title of Experiment Develop a JavaScript to implement a function.

Theory:

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 ().

Function names can contain letters, digits, underscores, and dollar signs
(same rules as variables).

The parentheses may include parameter names separated by commas:


(parameter1, parameter2, ...)

The code to be executed, by the function, is placed inside curly brackets: {}

Function Invocation
The code inside the function will execute when "something" invokes (calls)
the function:

 When an event occurs (when a user clicks a button)


 When it is invoked (called) from JavaScript code
 Automatically (self invoked)

Function Return
When JavaScript reaches a return statement, the function will stop
executing.

Page | 1
If the function was invoked from a statement, JavaScript will "return" to
execute the code after the invoking statement.

Functions often compute a return value. The return value is "returned" back
to the "caller":

Syntax

function name(parameter1, parameter2, parameter3) {


  // code to be executed
}

Example
var x = myFunction(4, 3);   // Function is called, return value will end
up in x

function myFunction(a, b) {
  return a * b;             // Function returns the product of a and b
}

Program:

Function calling without parameter:-

<html>

<head>

<title>Function Calling Using HTML</title>

<script type="text/javascript">

function Check()

var a=parseInt(prompt("Enter the number to check"));

if (a% 2==0)

document.write(a+ "number is even");

else

Page | 2
document.write(a+ "number is odd");

</script>

</head>

<body>

<h1> Click the Button!!!!</h1>

<!--input type="button" name="b1" value="Check even/odd" onClick="Check()"/-->

<script type="text/javascript">

Check();

</script>

</body>

</html>

Output:

Page | 3
Page | 4
Function calling with parameter:-

<html>

<head>

<title>Function Calling Using HTML</title>

<script type="text/javascript">

function Check()

var a=parseInt(prompt("Enter the number to check"));

if (a% 2==0)

document.write(a+ "number is even");

else

document.write(a+ "number is odd");

</script>

</head>

<body>

<h1> Click the Button!!!!</h1>

<input type="button" name="b1" value="Check even/odd" onClick="Check()"/>

</body>

</html>

Page | 5
Output:

Page | 6
Caller Program

<html>

<head>

<script type="text/javascript">

function prim(x,y)

varargs=prim.arguments;

document.write("prim caller"+prim.caller+"<br>");

document.write("prim argument length is:"+prim.arguments.length+"<br>");

for(vari=0;i<args.length;i++)

document.write("argument"+i+"is"+args[i]+"<br>");

function sec(x,y,z)

var d= new Date();

varyr = d.getFullYear();

prim(x,y,z,yr);

Page | 7
}

</script>

</head>

<body>

<script type="text/javascript">

prim(1,"two",3);

sec(4,"five",6,"seven");

</script>

</body>

</html>

Output:

Grade and C (35 M) P (15 M) Total ( 50 M) Dated Sign


Dated
Signature of
Teacher

Page | 8

You might also like