Table of Contents
hide
Example : A JS Program to print a message using the (No Argument No Return) Function.
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg()
{
document.write("Hello India");
//console.log("Hello India");
}
</script>
</head>
<body>
<script>
msg();
</script>
</body>
</html>
Example : A JS Program to display an output of given Input using the (With Argument No Return) Function.
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg(cname)
{
document.write("I am "+ cname);
}
</script>
</head>
<body>
<script>
msg("Indian");
</script>
</body>
</html>
-------------------------- OR --------------------------
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg(cname)
{
document.write("I am "+ cname);
}
msg("Bhartiya Indian");
</script>
</head>
</html>
Output:
Function Examples
I am Bhartiya Indian
-------------------------- OR --------------------------
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg(name)
{
document.write("The student name is = "+ name);
}
</script>
</head>
<body>
<script>
var sname=prompt("Enter a student name");
msg(sname);
</script>
</body>
</html>
Example : A JS Program to display a return output of given Input using the (With Argument With Return) Function.
<html>
<head>
<h4>Function Examples</H4>
<script>
function si( p, r, t )
{
var result = (p * r * t)/ 100;
return result;
}
</script>
</head>
<body>
<script>
var output = si( 5000, 10, 5);
document.write(output);
</script>
</body>
</html>
-------------------------- OR --------------------------
<html>
<head>
<h4>Function Examples</H4>
<script>
function si( p1, r1, t1 )
{
var result = (p1 * r1 * t1)/ 100;
return result;
}
</script>
</head>
<body>
<script>
var p=prompt("Enter the Principal value");
var r=prompt("Enter the rate value");
var t=prompt("Enter the time value");
var output = si( p, r, t);
document.write("The Simple Interest = " + output);
</script>
</body>
</html>
-------------------------- OR --------------------------
<html>
<head>
<h4>Function Examples</H4>
<script>
function si( p1, r1, t1 )
{
var result = (p1 * r1 * t1)/ 100;
return result;
}
</script>
</head>
<body>
<script>
var p=prompt("Enter the Principal value");
var r=prompt("Enter the rate value");
var t=prompt("Enter the time value");
document.write("The Simple Interest = " + si( p, r, t));
</script>
</body>
</html>
-------------------------- OR --------------------------
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg(cname)
{
document.write("I am an " + cname);
return;
}
</script>
</head>
<body>
<script>
msg("Indian");
</script>
</body>
</html>
Example : A JS Program to display a return output of Input using the (No Argument With Return) Function.
<html>
<head>
<h4>Function Examples</H4>
<script>
function si( )
{
var p, r, t;
p=5000; r=5;t=3;
var result = (p * r * t)/ 100;
return result;
}
</script>
</head>
<body>
<script>
var output = si();
document.write(output);
</script>
</body>
</html>
Example : A JS Program to display an output using Event Handler.
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg()
{
document.write("Hello India");
}
</script>
</head>
<body>
<input type="button" onclick="msg()" value="Message Show">
</body>
</html>
-------------------------- OR --------------------------
<html>
<head>
<h4>Function Examples</H4>
<script>
function msg(name,x)
{
document.write("The output is =" +name+" "+x);
}
</script>
</head>
<body>
<input type="button" onclick="msg('India',100)" value="Message Show">
</body>
</html>
0 Comments