0% found this document useful (0 votes)
2 views4 pages

Practical No4

Uploaded by

tanmayballal007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Practical No4

Uploaded by

tanmayballal007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No.

4
1.Program for simple function:
<html>
<script>
function msg()
{
alert("Hello! this is a message");
}
</script>
<input type="button" onclick="msg()" value="call function"/>
</html>
OUTPUT:

2.Program for function with argument:


<html>
<script>
function getCube(number)
{
alert("cube:"+number*number*number)
}
</script>
<form>
<input type="button" value="click" onclick="getCube(3)"/>
</form>
<html>
OUTPUT:
3.Program for function with return value:
<html>
<script>
function getInfo()
{
return"Hello Javapoint! How are you?";
}
</script>
<script>
document.write(getInfo());
</script>
</html>
OUTPUT:

4.Program for Fibonacci number using function


<html>
<head>
<title>Fibonacci series</title>
</head>
<script>
var num1=0;
var num2=1;
var sum=0,num=0;
num=prompt("enter number:",0);
function Fibonacci()
{
for(var i=1;i<=num;i++)
{
document.write(" "+sum);
sum=num1+num2;
num1=num2;
num2=sum;
}
}
document.write(Fibonacci())
</script>
</html>
OUTPUT:

5.Program for factorial using function


<html>
<head>
<title>factorial number</title>
</head>
<script>
var n=0;
n=prompt("enter number:",0);
var num1=0;
var num2=1;
var ans=1;
function factorial()
{
for(var i=2;i<=n;i++)
{
ans=ans*i
}
document.write(ans);
}
document.write(factorial());
</script>
</html>
OUTPUT:

You might also like