Filename: functions.js
====================================
// JavaScript Document
// Function With no Arguments and no return type
function line1() // called function
{
document.write("<br/>**********################***********<br/>");
}
// Function With Arguments and no return type
function line(s, n) // called function
{
document.write("<br/>");
for(i=0; i<n; i++) {
document.write(s);
}
document.write("<br/>");
}
// Function With both Arguments and return type
function clac(x, s, y) // called function
{
switch(s)
{
case '+': return(x+y); break;
case '-': return(x-y); break;
case '*': return(x*y); break;
case '/': return(x/y); break;
case '%': return(x%y); break;
}
}
===========================
File Name: Ext-jsfun-htmlpage.html
<head>
<script src="functions.js" type="text/javascript">
</script>
</head>
<body>
<script>
line1();
res=clac(5, '*', 80); // calling function
document.write("<br/>Res="+ res);
line('$', 50);
document.write("<br/>ANs=" + clac(52, '/', 3));
</script>
</body>
Output:
**********################***********
Res=400
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
ANs=17.333333333333332
====================================
// JavaScript Document
// Function With no Arguments and no return type
function line1() // called function
{
document.write("<br/>**********################***********<br/>");
}
// Function With Arguments and no return type
function line(s, n) // called function
{
document.write("<br/>");
for(i=0; i<n; i++) {
document.write(s);
}
document.write("<br/>");
}
// Function With both Arguments and return type
function clac(x, s, y) // called function
{
switch(s)
{
case '+': return(x+y); break;
case '-': return(x-y); break;
case '*': return(x*y); break;
case '/': return(x/y); break;
case '%': return(x%y); break;
}
}
===========================
File Name: Ext-jsfun-htmlpage.html
<head>
<script src="functions.js" type="text/javascript">
</script>
</head>
<body>
<script>
line1();
res=clac(5, '*', 80); // calling function
document.write("<br/>Res="+ res);
line('$', 50);
document.write("<br/>ANs=" + clac(52, '/', 3));
</script>
</body>
Output:
**********################***********
Res=400
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
ANs=17.333333333333332
No comments:
Post a Comment