Jsprogram
Jsprogram
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Area of rectangle</title>
</head>
<body>
<script type="text/javascript">
var length,width,area;
area=length*width;
document.write("Area of Rectangle="+area);
</script>
</body>
</html>
Result:
Exercise: 2
Objective:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Even/Odd</title>
</head>
<body>
<script type="text/javascript">
var n;
if(n%2==0)
else
</script>
</body>
</html>
Result:
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Largest</title>
</head>
<body>
<script type="text/javascript">
var x,y,z;
if(x>y)
if(x>z)
document.write(x+" is largest");
else
document.write(z+" is largest");
}
}
else
if(y>z)
document.write(y+" is largest");
else
document.write(z+" is largest");
</script>
</body>
</html>
Result:
Exercise: 4
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Vowels</title>
</head>
<body>
<script type="text/javascript">
var ch;
if(ch=='a')
document.write("a is a vowel");
else if(ch=='e')
document.write("e is a vowel");
else if(ch=='i')
document.write("i is a vowel");
else if(ch=='o')
document.write("o is a vowel");
else if(ch=='u')
document.write("u is a vowel");
}
else
</script>
</body>
</html>
Result:
Exercise: 5
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>day in a week</title>
</head>
<body>
<script type="text/javascript">
var d;
switch(d)
case 1:
document.write("Sunday");
break;
case 2:
document.write("Monday");
break;
case 3:
document.write("Tuesday");
break;
case 4:
document.write("Wednesday");
break;
case 5:
document.write("Thursday");
break;
case 6:
document.write("Friday");
break;
case 7:
document.write("Saturday");
break;
default:
document.write("Invalid day");
</script>
</body>
</html>
Result:
Exercise: 6
Objective:
Write a program to check whether a number is Armstrong or not using while loop.
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Armstrong or not</title>
</head>
<body>
<script type="text/javascript">
var n,sum=0,r,temp;
temp=n;
while(n>0)
r=n%10;
sum=sum+(r*r*r);
n=parseInt(n/10);
if(temp==sum)
else
</script>
</body>
</html>
Result:
Exercise: 7
Objective:
Write a program to check whether a number palindrome or not using do while loop.
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Palindrome or not</title>
</head>
<body>
<script type="text/javascript">
var n,rev=0,r,temp;
temp=n;
do
{
r=n%10;
rev=rev*10+r;
n=parseInt(n/10);
while(n>0);
if(temp==rev)
else
</script>
</body>
</html>
Result:
Exercise: 8
Objective:
Write a program to check whether a number is prime or not using for loop.
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Prime or not</title>
</head>
<body>
<script type="text/javascript">
var i,n,temp=0;
for(i=2;i<n;i++)
if(n%i==0)
temp=1;
if(temp==0)
else
</script>
</body>
</html>
Result:
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>factorial</title>
</head>
<body>
<script type="text/javascript">
var i,n,fact=1;
for(i=1;i<=n;i++)
fact=fact*i;
document.write("Factorial="+fact)
</script>
</body>
</html>
Result:
* *
* * *
* * * *
* * * * *
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>pattern</title>
</head>
<body>
<script type="text/javascript">
var i,j,n;
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
document.write("*");
document.write("<br>");
}
</script>
</body>
</html>
Result:
Exercise: 11
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>natural number</title>
</head>
<body>
<script type="text/javascript">
function num(n)
var i;
for(i=1;i<=n;i++)
document.write(i+"<br>");
}
var n;
num(n);
</script>
</body>
</html>
Result:
Exercise: 12
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Search Array</title>
</head>
<body>
<script type="text/javascript">
var i,n,temp=0,len,n;
var ar=[5,10,15,30,45,75,100,34,2,90];
len=ar.length;
for(i=0;i<len;i++)
{
if(n==ar[i])
temp=1;
break;
if(temp==1)
else
</script>
</body>
</html>
Result:
Exercise: 13
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>Reverse number</title>
</head>
<body>
<script type="text/javascript">
function reverse()
var n,r,rev=0;
n=parseInt(input.value);
while(n>0)
r=n%10;
rev=rev*10+r;
n=parseInt(n/10);
output.value=rev;
</script>
</body>
</html>
Result:
Objective:
Apparatus Required:
Procedure
<!DOCTYPE html>
<html>
<head>
<title>calculator</title>
</head>
<body>
<table><tr><td>
<script type="text/javascript">
function sum()
var a,b,c;
a=parseInt(txt1.value);
b=parseInt(txt2.value);
c=a+b;
txt3.value=c;
function sub()
var a,b,c;
a=parseInt(txt1.value);
b=parseInt(txt2.value);
c=a-b;
txt3.value=c;
function mult()
var a,b,c;
a=parseInt(txt1.value);
b=parseInt(txt2.value);
c=a*b;
txt3.value=c;
function div()
var a,b,c;
a=parseInt(txt1.value);
b=parseInt(txt2.value);
c=a/b;
txt3.value=c;
}
</script>
</body>
</html>
Result: