Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

Javascript Program Converted

Uploaded by

rupesh457809
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)
27 views

Javascript Program Converted

Uploaded by

rupesh457809
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/ 13

Javascript program

1) Write a javascript event driven program to change given text

<!doctype Html>
<html>
<head><title>change text property</title>
<script type="text/javascript">
function chgtxt( )
{
var a="<h1 style='color:red'>";
var b="Welcome to the HTML5 And Javascript";
var c="</h1>";
document.getElementById('para').innerHTML=a+b+c;

}
</script>
</head>
<body bgcolor="cyan">
<h1 align ="center">Change given text by using getElementById property</h1>
<p id="para">Welcome To the Site</p>
<form>
<input type="button" name="b1" onclick="chgtxt( )" value="Change Text">
</form>
</body>
</html>
2) write a event driven program to check eligibility for driving licence.

<!doctype html>
<html>
<head>
<title>check driving age</title>
<script type="text/javascript">
function age( )
{
var age;
age=parseInt(f1.t1.value);

if(age>=18)
{
alert("Qualifies for driving");
}
else
{
alert("Does not qualifies for driving");
}
}
</script>
</head>

<body bgcolor="pink">
<h1 align="center"> program to check qualify for driving</h1>
<form name="f1">
Enter age:<input type="text" name="t1"><br><br>

<input type="button" name="b1" value="check Qualify Result" onClick="age( )"><br>


</form>
</body>
</html>
3) write java script event driven program to print square of given no

<html>
<head>
<title>print square of given no</title>
<script type="text/javascript">
function sqr( )
{
var res,n;
n=parseInt(f1.t1.value);
res=n*n;
document.getElementById('sqrno').value=res;
}
</script>
</head>
<body bgcolor="pink">
<form name="f1">
<h1 align="center">print Square of given no </h1>
Enter A Number:<input type="text" name="t1"><br>
Square of given No :<input type="text" name="txt" id="sqrno" ><br>
<input type="button" name="b1" onclick="sqr( )" value="Square of Given no">

</form>

</body>
</html>
4) Write javascript event driven program to print factorial of given no

<!doctype html>
<html>
<head>
<title>print factorial of given no</title>
<script type="text/javascript">
function fact( )
{
var i,a=1,n;
n=parseInt(f1.t1.value);
f1.t2.value=n;
i=1;
while(i<=n)
{
a=a*i;
i=i+1;
}

f1.t3.value=a;

}
</script>
</head>
<body bgcolor="pink">
<h1 align="center"> print factorial of given no</h1>
<form name="f1">
Enter A number:<input type="text" name="t1"><br><br>
Given Number is:<input type="text" name="t2"><br><br>
Factorial of given no is:<input type="text" name="t3"><br><br>
<input type="button" name="b1" value="find factorial" onClick="fact( )"><br>
</form>
</body>
</html>
5) Write a javascript program to check given number is prime or not.

<!doctype html>
<html>
<head>
<title>check prime no</title>
<script type="text/javascript">
function prime( )
{
var a,ans,i;
a=parseInt(f1.t1.value);
ans=1;
for(i=2;i<a;i++)
{
if(a%i==0)
{
ans=0;
break;
}
}
if(ans==1)
f1.t3.value="Given Number Is Prime";
else
f1.t3.value="Given Number Is not Prime";

}
</script>
</head>
<body bgcolor="pink">
<h1 align="center"> program to check of given no is prime or not</h1>
<form name="f1">
Enter A number:<input type="text" name="t1"><br><br>
check given no is prime or not :<input type="text" name="t3"><br><br>
<input type="button" name="b1" value="check prime" onClick="prime( )"><br>
</form>
</body>
</html>
6) Write a javascript program even number in 51 to 70.

<!doctype html>
<html>
<head>
<title>print even no in 51 to 70 no </title>
<script type="text/javascript">
function even( )
{
var i,a;
for(i=51;i<=70;i++)
{
a=i%2;
if(a==0)
{
document.writeln(i);
document.writeln("<br>");
}
}
}
</script>
</head>

<body bgcolor="pink">
<h1 align="center">print 51to 70 no by using for loop</h1>
<form name="f1">
<input type="button" name="bt1" onclick="even( )" value="print even number">
</form>

</body>
</html>
7) Write a javascript program to print odd number in 40 to 60.

<!doctype html>
<html>
<head>
<title>print odd no in 40 to 60 no by using for loop</title>
<script type="text/javascript">
function even( )
{
var i,a;
for(i=40;i<=60;i++)
{
a=i%2;
if(a==1)
{
document.writeln(i);
document.writeln("<br>");
}
}
}
</script>
</head>

<body bgcolor="pink">
<h1 align="center">print 51 to 70 no by using for loop</h1>
<form name="f1">
<input type="button" name="bt1" onclick="even( )" value="print odd number">
</form>

</body>
</html>
8) Write a javascript program to display table of any number..

<!doctype html>
<html>
<head>
<title>print table of any number </title>
<script type="text/javascript">
function disp( )
{

var i,a,b;
a=parseInt(f1.t1.value);
document.write("Table of number......"+a+"<br>");
for(i=1;i<=10;i++)
{
b=a*i;
document.write(b);
document.write("<br>");
}

}
</script>
</head>

<body bgcolor="pink">
<h1 align="center">print table of any number</h1>
<form name="f1">
Enter A number:<input type="text" name="t1"><br><br>
<input type="button" name="bt1" onclick="disp( )" value="print table of any number">
</form>

</body>
</html>
9)Write javascript event driven program to display addition and substraction of two
numbers,which were accepted from user.

<!doctype html>
<html>
<head>
<title>print simple calculator </title>
<script type="text/javascript">
function add( )
{
var a,b,c;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
c=a+b;
f1.t3.value=c;
}
function sub( )
{
var a,b,c;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
c=a-b;
f1.t3.value=c;
}
</script>
</head>
<body bgcolor="pink">
<h1 align="center">print addition and Substraction</h1>
<form name="f1">
Enter first number:<input type="text" name="t1"><br><br>
Enter Second number:<input type="text" name="t2"><br><br>
result <input type="text" name="t3"><br><br>
<input type="button" name="bt1" onclick="add( )" value="Addition">
<input type="button" name="bt1" onclick="sub( )" value="Substration">
</form>

</body>
</html>
10) Write javascript event driven program to display Multiplication and Division of two
numbers,which were accepted from user.
<!doctype html>
<html>
<head>
<title>print simple calculator </title>
<script type="text/javascript">
function multi( )
{

var a,b,c;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
c=a+b;
f1.t3.value=c;

}
function division( )
{

var a,b,c;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
c=a/b;
f1.t3.value=c;

</script>
</head>
<body bgcolor="pink">
<h1 align="center">print addition and Substraction</h1>
<form name="f1">
Enter first number:<input type="text" name="t1"><br><br>
Enter Second number:<input type="text" name="t2"><br><br>
<input type="button" name="bt1" onclick="multi( )" value="Addition">
<input type="button" name="bt2" onclick="division( )" value="Substration">
</form>
</body>
</html>
11) Write javascript event driven program to display Multiplication and Division of two
numbers,which were accepted from user.

<!doctype html>
<html>
<head>
<title>print number is positive or not</title>
<script type="text/javascript">
function chkdisp( )
{
var a;
a=parseInt(f1.t1.value);
if(a<0)
{

f1.t2.value="Number"+a+" is positive";
}
else
{
f1.t2.value="Number"+a+" is Negative";
}
}
</script>
</head>
<body bgcolor="pink">

<h1 align="center">program to check positive or negative</h1>


<form name="f1">
Enter a number :<input type="text" name="t1"><br><br>
check positive or negative:<input type="text" name="t2"><br><br>

<input type="button" name="b1" value="check positive or negative"


onclick="chkdisp( )">

</body>
</html>
12) Write javascript event driven program to display area ofcircle which were accepted
from user.

<!doctype html>
<html>
<head>
<title>print area of circle</title>
<script type="text/javascript">
function area( )
{
var p,a,r;
p=3.147;
r=parseInt(f1.t1.value);
a=p*r*r;
f1.t2.value=a;
}
</script>
</head>
<body bgcolor="pink">

<h1 align="center">program to find Area of Circle</h1>


<form name="f1">
Enter a radius :<input type="text" name="t1"><br><br>
Area Of Circle:<input type="text" name="t2"><br><br>
<input type="button" name="b1" value="Area Of circle" onclick="area( )">

</body>
</html>
13) Write javascript event driven program to display series 101,102….

<!doctype html>
<html>
<head>
<title>print series 101 </title>
<script type="text/javascript">
function disp( )
{
var i;
for(i=100;i<=150;i++)
{

document.writeln("\t"+i);

}
</script>
</head>

<body bgcolor="pink">
<h1 align="center">print series 101,102....</h1>
<form name="f1">
<input type="button" name="bt1" onclick="disp( )" value="print series">
</form>

</body>
</html>

You might also like