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

Javascript Imp Programs

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

Javascript Imp Programs

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

JAVASCRIPT PROGRAMS

Q.1) Write event driven JavaScript program to accept three numbers from user and perform
Addition and Multiplication of it.

<!doctype html>
<html>
<head>
<title>Add and Mul Demo</title>
<script type="text/javascript">
function display()
{
var no1,no2,no3,add,mul;
no1=parseInt(form1.t1.value);
no2=parseInt(form1.t2.value);
no3=parseInt(form1.t3.value);
add=no1+no2+no3;
mul=no1*no2*no3;
alert("Addition of three numbers is :" +add);
alert("Multiplication of three numbers is :" +mul);
}
</script>
</head>
<body>
<form name=form1>
Enter first number:<input type=text name=t1><br>
Enter second number:<input type=text name=t2><br>
Enter third number:<input type=text name=t3><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

1
Q.2) Write event driven JavaScript program to accept radius from user and calculate area of
circle.(π =3.14, area=π*radius*radius)

<!doctype html>
<html>
<head>
<title>Area Of Circle Demo</title>
<script type="text/javascript"> function display()
{
var r,area;
r=form1.t1.value;
area=3.14*r*r;
alert("Area is : " +area);
}
</script>
</head>
<body>
<form name=form1>
Enter radius of Circle:
<input type=text name=t1><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

Q.3 ) Write event driven JavaScript program to accept number from user and find cube
of accepted number.

<!doctype html>
<html>
<head>
<title>Cube Demo</title>
<script type="text/javascript">
function display()
{
var a,cube;
a=parseInt(form1.t1.value);
cube=a*a*a;
alert("Cube of accepted number is "+cube);
}
</script>
</head>
<body>
<form name=form1>
Enter one number to find Cube:<input type=text name=t1><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

2
Q. 4) Write event driven JavaScript program to accept two numbers from user and
perform Division and Subtraction of accepted numbers.
<!doctype html>
<html>
<head>
<title>Div and Sub Demo</title>
<script type="text/javascript">
function display()
{
var no1,no2,div,sub;
no1=parseInt(form1.t1.value);
no2=parseInt(form1.t2.value);
div=no1/no2;
sub=no1-no2;
alert("Division is :" +div);
alert("Substraction is :" +sub);
}
</script>
</head>
<body>
<form name=form1>
Enter first number:
<input type=text name=t1><br>
Enter second number:<input type=text name=t2><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

Q.5) Write event driven JavaScript program to accept number from user and make a double
of it
<!doctype html>
<html>
<head>
<title>Double of Number Demo</title>
<script type="text/javascript">
function display()
{
var a,res;
a=parseInt(form1.t1.value);
res=a+a;
alert("Double of accepted number is "+res);
}
</script>
</head>
<body>
<form name=form1>
Enter one number to find double of it:<input type=text name=t1><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

3
Q.6) Write event driven JavaScript program to display even numbers from 1 to 10.
<!doctype html>
<html>
<head>
<title>Even Number Demo</title>
<script type="text/javascript"> function display()
{
var i;
for(i=1;i<=10;i++)
if(i%2==0)
{
document.writeln(i+"<br>");
}
}
</script>
</head>
<body>
<form name=form1> Click button to display even numbers from 1 to 10<br>
<input type=submit onClick="display()">
</form>
</body>
</html>

Q.7) Write event driven JavaScript program to display whether the accepted number is
EVEN or ODD.
<!doctype html>
<html>
<head>
<title>Even Odd Demo</title>
<script type="text/javascript">
function display()
{
var num1;
num1=form1.t1.value;
if(num1%2==0)
alert("Number is Even");
else
alert("Number is Odd");
}
</script>
</head>
<body>
<form name=form1>
Enter one number:
<input type=text name=t1>
<input type=submit onClick="display()">
</form>
</body>
</html>

4
Q.8) Write event driven JavaScript program to accept two integers and display larger
number of them.

<!doctype html>
<html>
<head>
<title>Greater Number Demo</title>
<script type="text/Javascript">
function display()
{
var num1,num2;
num1=parseInt(form1.t1.value);
num2=parseInt(form1.t2.value);
if(num1>num2)
alert("Greater number is "+num1);
else
alert("Greater number is "+num2);
}
</script>
</head>
<body>
<form name=form1>
Enter first number :
<input type=text name=t1><br>
Enter second number :
<input type=text name=t2><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

Q.9) Write event driven JavaScript program to accept one integer from user and check
whether the accepted number is greater than less than or equal to 100.

<!doctype html> }
<html> </script>
<head> </head>
<title>Comparison with 100 <body>
Demo</title> <form name=form1>
<script type="text/javascript"> Enter one number :
function display() <input type=text name=t1><br>
{ <input type=submit onClick="display()">
var no1; </form>
no1=parseInt(form1.t1.value); </body>
if(no1>100) </html>
alert("Number is greater than 100
ie."+no1);
else if(no1<100)
alert("Number is less than 100
ie."+no1);
else
alert("Number is equal to 100");

5
Q.10) Write event driven JavaScript program to accept integer from user and find square
of it.

<!doctype html>
<html>
<head>
<title>Square Demo</title>
<script type="text/javascript">
function display()
{
var a,sqr;
a=form1.t1.value;
sqr=a*a;
alert("Square of accepted number is "+sqr);
}
</script>
</head>
<body>
<form name=form1>
Enter one number to find square:
<input type=text name=t1><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

Q.11) Write event driven JavaScript program to accept integer from user and display table
of it.
<!doctype html>
<html>
<head>
<title>Table Demo</title>
<script type="text/javascript">
function display()
{
var i,no1,table;
no1=form1.t1.value;
for(i=1;i<=10;i++)
{
table=i*no1;
document.writeln(table+"<br>");
}
}
</script>
</head>
<body>
<form name=form1>
Enter one number to display table:
<input type=text name=t1><br>
<input type=submit onClick="display()">
</form>
</body>
</html>

6
Q. 12) Write event driven JavaScript program to accept height and base from the user and
find area of triangle. (Area=1/2*base*height).
<!doctype html>
<html>
<head>
<title>Area Of Triangle</title>
<script type="text/javascript">
function display()
{
var height,base,area;
height=form1.t1.value;
base=form1.t2.value;
area=1/2*height*base;
alert("Area of Triangle : " +area);
}
</script>
</head>
<body>
<form name=form1>
Enter height:
<input type=text name=t1><br>
Enter base:
<input type=text name=t2><br>
<input type=submit onClick="display()">
</form>
</body>
</html>
Q. 13) Find and Display Factorial of given number.

<!DOCTYPE html>
<html><head><title>Prime number</title></head>
<body>
<form name="f1">
<input type="number" name="t1"><br>
<input type="button" name="b1" value="factorial" onMouseOver="fact()">
</form>
</body>
<script type="text/javascript">
function fact()
{
var a,f=1,i;
a=parseInt(f1.t1.value);
for(i=a;i>=1;i--)
{
f=f*i;
}
alert("Factorial of a number is "+f);
}
</script>
</html>

7
Q. 14) Accept any string from user & count display number of vowels occurs in it.

<!DOCTYPE html>
<html>
<script type="text/javascript">
var n,i,ch,cnt=0;
n=prompt("Enter a string");
for(i=0;i<n.length;i++)
{
ch=n.charAt(i);
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{
cnt=cnt+1;
}
}
document.write("Number of vowels in string are "+cnt);
</script>
</html>

Q. 15) Display number sequence from 100 to 150 in following format.

<!Doctype html>
<html>
<Head><title>Display numbers</title>
<script type="text/javascript">
function dis()
{
var i=1
for(i=100;i<=150;i++)
{
document.write(i+" ");
}
}
</script>
</Head>
<body>
<form name="f1">
<input type="button" value="display Numbers" onClick="dis()">
</form>
</body>
</html>

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