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

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 views

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy