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

Jsprogram

The document contains 11 coding exercises with the objective, required apparatus, coding procedures and results for each exercise. The exercises cover topics like finding the area of a rectangle, checking if a number is even or odd, finding the largest of three numbers, identifying vowels, using switch statements to print the day of the week, checking if a number is Armstrong, checking if a number is a palindrome using loops, checking if a number is prime, finding the factorial of a number, printing patterns with loops, and printing sums using functions.

Uploaded by

binila1125
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Jsprogram

The document contains 11 coding exercises with the objective, required apparatus, coding procedures and results for each exercise. The exercises cover topics like finding the area of a rectangle, checking if a number is even or odd, finding the largest of three numbers, identifying vowels, using switch statements to print the day of the week, checking if a number is Armstrong, checking if a number is a palindrome using loops, checking if a number is prime, finding the factorial of a number, printing patterns with loops, and printing sums using functions.

Uploaded by

binila1125
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Exercise: 1

Objective:

Write a program to find area of rectangle.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>Area of rectangle</title>

</head>

<body>

<script type="text/javascript">

var length,width,area;

length=parseInt(prompt("Enter the length"));

width=parseInt(prompt("enter the width "));

area=length*width;

document.write("Area of Rectangle="+area);

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 2

Objective:

Write a program to check whether a number is even or odd.


Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>Even/Odd</title>

</head>

<body>

<script type="text/javascript">

var n;

n=parseInt(prompt("Enter the number"));

if(n%2==0)

document.write(n+" is even number");

else

document.write(n+" is odd number");

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.


Exercise: 3

Objective:

Write a program to check whether Largest of 3 numbers.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>Largest</title>

</head>

<body>

<script type="text/javascript">

var x,y,z;

x=parseInt(prompt("Enter the first number"));

y=parseInt(prompt("Enter the second number"));

z=parseInt(prompt("Enter the third number"));

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:

The program is successfully executed and the output is produced.

Exercise: 4

Objective:

Write a program to print vowel in an alphabet using multiple if.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>
<head>

<title>Vowels</title>

</head>

<body>

<script type="text/javascript">

var ch;

ch=prompt("Enter the first number");

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

document.write("it is not a vowel");

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 5

Objective:

Write a program to print day in a week using switch statement.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>day in a week</title>

</head>

<body>

<script type="text/javascript">

var d;

d=parseInt(prompt("Enter the day number"));

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:

The program is successfully executed and the output is produced.

Exercise: 6

Objective:

Write a program to check whether a number is Armstrong or not using while loop.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>Armstrong or not</title>

</head>

<body>

<script type="text/javascript">

var n,sum=0,r,temp;

n=parseInt(prompt("Enter the number"));

temp=n;

while(n>0)

r=n%10;

sum=sum+(r*r*r);

n=parseInt(n/10);

if(temp==sum)

document.write(temp+" is an armstrong number");


}

else

document.write(temp+" is not an armstrong number");

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 7

Objective:

Write a program to check whether a number palindrome or not using do while loop.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>Palindrome or not</title>

</head>

<body>

<script type="text/javascript">

var n,rev=0,r,temp;

n=parseInt(prompt("Enter the number"));

temp=n;

do
{

r=n%10;

rev=rev*10+r;

n=parseInt(n/10);

while(n>0);

if(temp==rev)

document.write(temp+" is a palindrome number");

else

document.write(temp+" is not a palindrome number");

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 8

Objective:

Write a program to check whether a number is prime or not using for loop.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>
<head>

<title>Prime or not</title>

</head>

<body>

<script type="text/javascript">

var i,n,temp=0;

n=parseInt(prompt("Enter the number"));

for(i=2;i<n;i++)

if(n%i==0)

temp=1;

if(temp==0)

document.write(n+" is a prime number");

else

document.write(n+" is not a prime number");

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.


Exercise: 9

Objective:

Write a program to find factorial of a number using for loop.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>factorial</title>

</head>

<body>

<script type="text/javascript">

var i,n,fact=1;

n=parseInt(prompt("Enter the number"));

for(i=1;i<=n;i++)

fact=fact*i;

document.write("Factorial="+fact)

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.


Exercise: 10

Objective: Write a program to print the following pattern.

* *

* * *

* * * *

* * * * *

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>pattern</title>

</head>

<body>

<script type="text/javascript">

var i,j,n;

n=parseInt(prompt("Enter the number"));

for(i=1;i<=n;i++)

for(j=1;j<=i;j++)

document.write("*");

document.write("<br>");

}
</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 11

Objective:

Write a program to print sum of n natural number using function..

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

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;

n=parseInt(prompt("Enter the number"));

num(n);

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 12

Objective:

Write a program to print search an elements from an array.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser.

Procedure

<!DOCTYPE html>

<html>

<head>

<title>Search Array</title>

</head>

<body>

<script type="text/javascript">

var i,n,temp=0,len,n;

n=parseInt(prompt("Enter the number to be searched"));

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)

document.write(n+" Element Found at position "+(i+1));

else

document.write(n+" not found");

</script>

</body>

</html>

Result:

The program is successfully executed and the output is produced.

Exercise: 13

Objective:

Write a program to print reverse of a number using form.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>
<head>

<title>Reverse number</title>

</head>

<body>

Enter the number<input type="text" id="input"><br>

Reverse<input type="text" id="output"><br>

<input type="button" value="find" onClick="reverse()">

<input type="Reset" value="clear">

<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:

The program is successfully executed and the output is produced.


Exercise: 14

Objective:

Write a program to print simple calculator.

Apparatus Required:

Text editors(Notepad, Sublime text), Browser

Procedure

<!DOCTYPE html>

<html>

<head>

<title>calculator</title>

</head>

<body>

<table><tr><td>

Enter the First No</td><td><input type="number" id="txt1"></td></tr>

<tr><td>Enter the Second No</td><td><input type="number" id="txt2"></td></tr>

<tr><td>Result</td><td><input type="number" id="txt3"></td></tr>

<tr><td><input type="button" value="Add" onclick="sum()">

<input type="button" value="Sub" onclick="sub()">

<input type="button" value="Mult" onclick="mult()">

<input type="button" value="Div" onclick="div()"></td><td>

<input type="reset" value="AC"> </td></tr></table>

<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:

The program is successfully executed and the output is produced.

You might also like