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

CSS_Exp 4_PDF_UPDATED TUESDAY

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

CSS_Exp 4_PDF_UPDATED TUESDAY

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

Name: Ansari Abdullah Roll no: 220402

Sub: Client-Side Scripting (CSS) Branch: CO

Experiment No. 4: Develop Javascript to implement functions


▪ Write a program to check whether the number is Palindrome or not using function

CODE:
<html>
<head>
<title> Palindrome </title>
<script>
var rem,rev=0,n,no,num;
function palindrome(num)
{
num=parseInt(prompt("Enter a no: "));
n=num
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=parseInt(num/10);
}
if(rev==n)
document.write(n+" is a palindrome");
else
document.write(n+" is not a palindrome");
}
palindrome(n);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>
OUTPUT:

▪ Write a program to reverse of n digit number using function


CODE:
<html>
<head>
<title> Reverse </title>
<script>
var rem,rev=0,n,no,num;
function reverse(num)
{
num=parseInt(prompt("Enter a no: "));
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=parseInt(num/10);
}
document.write("Reverse= "+rev);
}
reverse(n);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

▪ Write a program to print sum of n digit number using method

CODE:
<html>
<head>
<title> Sum </title>
<script>
var rem,sum=0,n,no,num;
var obj={sum:function(num)
{
num=parseInt(prompt("Enter a no: "));
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=parseInt(num/10);
}
document.write("Sum= "+sum+"<hr>");
}};
obj.sum(n);
document.write("220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

▪ Write a program to check whether number is an Armstrong or not using method

CODE:
<html>
<head>
<title> Armstrong </title>
<script>
var rem,sum=0,n,no,num;
var o={armstrong:function(num)
{
num=parseInt(prompt("Enter a no: "));
no=num;
while(no!=0)
{
rem=no%10;
sum=sum+(rem*rem*rem);
no=parseInt(no/10);
}
if(sum==num)
document.write(num+" is an armstrong no");
else
document.write(num+" is not an armstrong no");
}};
o.armstrong(n);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

▪ Write a program to print factorial series using constructor

CODE:
<html>
<head>
<title> Factorial series </title>
<script>
var i,num,n;
function fact(num)
{
var fact=1;
for(i=1;i<=num;i++)
{
fact=fact*i;
document.write(fact+" ");
}
document.write("<hr> 220402-Ansari Abdullah ");
}
var n=parseInt(prompt("Enter last position:"));
var x=new fact(n);
x.fact();
</script>
</head>
</html>

OUTPUT:
▪ Write a program to print fibonacci series using constructor

CODE:
<html>
<head>
<title> Fibo series </title>
<script>
var i,n,num;
var fno=0,sno=1;
var tno;
function fibo(num)
{
document.write(fno+ " " + sno+ " ");
for(i=3;i<=n;i++)
{
tno=fno+sno;
document.write(tno+" ");
fno=sno;
sno=tno;
}
document.write("<hr> 220402-Ansari Abdullah ");
}
var n=parseInt(prompt("Enter last position:"));
var x=new fibo(n);
x.fibo();
</script>
</head>
</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