0% found this document useful (0 votes)
5 views12 pages

Q.8 Java Script

The document contains a question bank of JavaScript programs focusing on event-driven programming. It includes examples for determining even/odd numbers, calculating sums, displaying areas and perimeters of shapes, and other mathematical operations. Each example is presented with HTML and JavaScript code snippets for practical implementation.

Uploaded by

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

Q.8 Java Script

The document contains a question bank of JavaScript programs focusing on event-driven programming. It includes examples for determining even/odd numbers, calculating sums, displaying areas and perimeters of shapes, and other mathematical operations. Each example is presented with HTML and JavaScript code snippets for practical implementation.

Uploaded by

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

Question 8

Java script Programs Question Bank

1) Write an event driven JavaScript programs to display whether accept number is even
or odd.
<!doctype html>
<html> <head>
<title> even odd </title>
<script language="javascript">
function even ()
{
var a;
a=parseInt([Link]);
if(a%2==0)
alert (" Number is even ");
else
alert (" number is odd");
}
</script> </head>
<body>
<form name ="f1">
Enter a Number <input type ="number"name="n1">
<input type ="button" name="b1" value= "odd even" onClick ="even() ">
</form>
</body></html>
2) Write an event driven JavaScript programs to display addition of number from 50 to 150
when the mouse is moved over.

<!doctype html>
<html> <head><title>addition of nos 50 to 150</title>
<script language="javascript">
function chk()
{
var i, sum=0;
for(i=50; i<=150;i++)
{
sum=sum +i;
}
alert ("Addition at nos. from 50 to 150 is" + sum);
}
</script ></head><body>
<form name ="f1">
<h1> Addition of nos. 50 to 150</h><br><br>
<input type ="button"name="b1" value= "calculate" onMouseOver="chk()">
</form>
</body>
</html>
3) Write an event driven JavaScript programs display even number between 50 to 150

<!doctype html>
<html> <head><title> even nos.</title>
<script type =”text / javascript”>
function chk()
{
Var i;
for(i=50; i<=150; i=i+2)
{
Document . write (i + “<br>”);
</script ></head><body>
<form name =”f1”>
<h1> even nos. between 50 to 150</h1>
<input type “button” value =”even” onMouseOver()=”chk()”>
</form>
</body>
</html>
4.) Write an event driven JavaScript programs display odd number between 50 to 150
<!doctype html>

<html> <head><title> even nos.</title>

<script language="javascript">

function chk()

{ var i;

for(i=50; i<=150; i=i+2)

[Link](i+ "<br>")

</script ></head><body>

<form name ="f1">

<h1> even nos. between 50 to 150</h1>

<input type ="button"value ="even"onMouseOver()="chk()">

</form>

</body>

</html>

5. Write an event driven JavaScript programs display cube at the accepted number when
the mouse is moved over a button.

<!doctype html>
<html> <head><title> odd nos.</title>
<script type =”text / javascript” >
function chk ()
{
var a, c;
a = parseInt([Link] );
c = a*a*a;
alert (“ cube at no is “,+c);
}
</script> </head> <body>
<form name =”f1”>
Enter Number
<Input type =”Number” name =”n1”><br>
<input type =”button” name=”b1” value =”cube” onMouseOver=”chk()” >
</form></body></html>

6 . Write an event driven JavaScript programs to display area at circle .Accept radius from
the user (area = 3.14*r*r)
<!doctype html>
<html><head><title> area at circle.</title>
<script type =”text/JavaScript” >
function area ()
{
var a,r,p=3.14;
r= parseInt ([Link] );
a= p*r*r;
alert (“area at circle .is “+a);
}
</script> </head> <body>
<form name =”f1”>
Enter radius <input type =”number “name =”n1”>
<input type =”submit” name =”b1” value =”Area at circle”onClick=”area()”>
</form></body></html>
7. Write an event driven JavaScript programs to display area at triangle .Accept base &
height from the use (area =1/2xbx h)

<!doctype html >


<html><head><title> area at the triangle < /title>
<script type =”text / JavaScript” >
function area ()
{
var b,h,a;
b= parseInt ([Link] );
h= parseInt ([Link] );
a= ½*b*h;
Alert(“Area at Triangle is “+a);
}
</script> </head> <body>
<form name =”f1”>
Enter base
<input type =”number “name =”n1”><br>
Enter height
<input type =”number “name =”n2”><br>
<input type “button” name=”b1” value =”Area of triangle” onClick =”area ()”>
</form></body></html>

8. Write an event driven JavaScript programs to display perimeter of a rectangle Accept


length & breadth from the user.( perimeter =2x length +2x Breadth)

<! doctype html >


<html><head><title> perimeter of rectangle < /title>
<script type =”text / JavaScript” >
function peri ()
{
var l,b,p;
l = parseInt ([Link] );
b= parseInt ([Link] );
p= (2*l) + (2*b);

alert (“perimeter at Rectangle is “+p);

</script> </head> <body>


<form name =”f1”>
Enter length
<Input type =”number” name =”n1”><br><br>
Enter breadth
<Input type =”number” name =”n2”><br><br>
<input type =”button” name =”b1” value =”perimeter of Rectangle “onClick =peri()’’>
</form></body></html>

9. Write an event driven JavaScript programs to display length at the text “Information
Technology” on click at a button.

<! doctype html >


<html><head><title> IT < /title>
<script type =”text / JavaScript” >
function info ()
{
var a;
a =”Information Technology”;
[Link] (“Length at string “,+a. length )
}
</script> </head> <body>
<form name =”f1”>
<input type = “button” value = “length” onClick = “info()”>
</form></body></html>

[Link] an event driven JavaScript programs to display tale of accept number .


(eg. 2x1=2 2x2=4 ---)
<! doctype html >
<html><head><title> table < /title>
<script type =”text / JavaScript” >
function table ()
{
var n,i,m;
N= parseInt (f1.n1 value)
For (i= 1; i<=10; i++)
}
m= n*i;
document write (n+ “x”+ i + “=”+m);
document .write(“<br>”);
}
</script> </head> <body>
<form name =”f1”>
Enter number
<input type = “number” name =”n1”><br>
<input type = “button” name =”b1” value = “table” onClick= “table()”>
</form></body></html>

11. Write an event driven JavaScript programs to display square root at a number using
built –in function of at math object.
<!doctype html >
<html><head><title> square root at number < /title>
<script type =”text / JavaScript” >
function r ()
{
var a;
a= f1.n1. value .
alert (“square root of no is “,+ [Link] (a));
}
</script> </head> <body>
<form name = “f1” >
Enter no <input type =”number” name “n1” >
<br>
<input type = “button” value =”square root” onClick= “r()”>
</form></body></html>

12. Write an event driven JavaScript programs to display 2 colors after every 3000
milliseconds. On click a button.

<!doctype html >


<html><head><title> color change < /title>
<script type =”text / JavaScript” >
function f1 ()
{
[Link]= “pink”
window. setTimeout (“f2()”, 3000);
}
function f2 ()
{
document. bgColor= “cyan”
Window. setTimeout (“f2()”, 3000);
}
</script> </head> <body>
<form name = “fr()”>
<input type =”button” name= “b1” value = “change colors” onClick = “f1()”>
</form></body></html>
13. Write an event driven JavaScript programs to accept pin code and check whether it is
an integer .
<!doctype html >
<html><head><title> pin code </title>
<script language =”text / JavaScript” >
function pin ()
{
var a;
a= f1.n1. value .
if (is NaN(a))
alert (“ pin code contains character”);
else
alert (“ pin code contains Integer”);
}
</script> </head> <body>
<form name = “f1”>
Enter pin code
<input type = “text” name = “n1”><br><br>
<input type = “button” name= “b1” value = “check” onClick = “pin ()”>
</form></body></html>
14. Write an event driven JavaScript programs to accept 2nos.& display which no is grater.
<!doctype html >
<html><head><title> no. grater < /title>
<script type =”text / JavaScript” >
function g ()
{
var a,b;
a= parseInt ([Link] );
b= parseInt ([Link] );
if (a>b)
alert (“Grater Number is “+a);
else
alert (“grater no is “+b);
}
</script> </head> <body>
<form name =”f1”>
Enter 1st number
<input type = “number “ name “n1”><br>
<input type = “number “ name “n2”><br>
<input type = “button”name = “b1” value = “Display Grater” onClick= “g()”>
</form></body></html>

15) Write a java script program for factorial of number 35


<!doctype html>
<html>
<head><title>odd number</title>
<script language="javascript">
function chk()
{
var i,a=35,f=1;
for(i=a;i>=1;i--)
{
f=f*i;
}
[Link]("factorial of number is"+f);
}
</script>
</head>
<body>
<h1 align="center">factorial of number</h1>
<form>
<input type="button" name="b1" value="factorial"onMouseOver="chk()">
</form>
</body>
</html>
OR
From user
<!doctype html>
<html>
<head><title>odd number</title>
<script language="javascript">
function chk()
{
var i,a,f=1;
a=prompt("enter number");
for(i=a;i>=1;i--)
{
f=f*i;
}
[Link]("factorial of number is"+f);
}
</script>
</head>
<body>
<h1 align="center">factorial of number</h1>
<form>
<input type="button" name="b1" value="factorial"onMouseOver="chk()">
</form>
</body>
</html>

Practice this type of examples of Javascript programs

You might also like