0% found this document useful (0 votes)
21 views9 pages

JavaScript Event-Driven Programs

The document provides several event-driven JavaScript programs that demonstrate basic functionalities such as checking if a number is even or odd, performing addition and subtraction of two numbers, calculating the sum of numbers within a range, and displaying even and odd numbers within specified limits. It also includes programs to calculate the area of a circle and a rectangle based on user input. Each program is accompanied by HTML and JavaScript code snippets for implementation.

Uploaded by

purest
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)
21 views9 pages

JavaScript Event-Driven Programs

The document provides several event-driven JavaScript programs that demonstrate basic functionalities such as checking if a number is even or odd, performing addition and subtraction of two numbers, calculating the sum of numbers within a range, and displaying even and odd numbers within specified limits. It also includes programs to calculate the area of a circle and a rectangle based on user input. Each program is accompanied by HTML and JavaScript code snippets for implementation.

Uploaded by

purest
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

whether accepted

2. Write an event driven JavaScript program to


display number is
even or odd.
Ans. :
Coding :
<DOCTYPE htm>
<html>

<body>
<form name="{1">
Enter aNumber
<input type="'number" name="n1'><br><br>
name="bl" value="Odd Even" onClick="even()"s
<input type="button"
</form>
</body>
<script type="text/javascript">
function even()

var a;
a=parselnt([Link]);
if(a%2==0)
oS Information Technology (Science) 3-54 Advanced JavaScript
alert("Number is Even number");
else
alert(""Number is Odd number"):
</script>
k/htmls
Output:
9 prg2 html

O File FTPS%202022-23/)avascript/[Link]
Enter a Number

Odd Even

3 Write an event driven JavaScript program to display addition and subtraction of


two accepted numberson click of a button.
Ans. :

Coding :
K!DOCTYPE html>
<html>
kbody>
<form name="{1">
Enter IstNumber
<input type="number" name=-nl"><br><br>
Enter IInd Number
Kinput type='number" name="n2"><br><br>
kinput type-"button" name="bl" value="Calculate" onClick="chk()'>
TPS Information Technology(Science) 3-55

</form>
</body>
Advanced ava,
<script typ="text/javascript'>
function chk()

var a,b,add,sub;
a=parselnt([Link]):
b=parselnt([Link]);
|add=a+b;
sub=a-b;
alert("Addition is "+add);
alert("Substraction is "+sub);

</script>
</html>

Output:
+
S prg2htm! X [Link] X

O Fite F/TPS%202022-23/Javascript/[Link]
Enter Ist Number

Enter lInd Number

Calculate
TPSInformation Technology (Science)
3-56 Advanced JavaScript
Write an event
driven JavaScript program to
150when the mouse is of numbers from 50
moved over a [Link]
4,
addition
Ans.:

Coding:
ADOCTYPEhtmls
chtmls

cbody>
cform name="f1"'
chl>Addition of Numbers from 50 to 150</hl>
kinputtype=""button" name="b1" value="Calculate" onMouseOver="chk()">
</form>
</body>
script type='text/javascript">
function chk)

vari,sum=0;
for(i=50;i<=150;i++)
sum=sum+i;

alert("Addition of Numbers from 50 to 150 is "+sum);

k/script>
k/html>
Output:
S prg4htmi
O file FTPS%202022-23/lavascript/[Link]

Addition of Numbers from 50 to 150


Calculete
TPS Information Technology (Science) 3-57
Advanced JavaScrip
5. Write an event driven JavaScript program to display even numbers between so,
150.
Ans. :
Coding :
<!DOCTYPE html>
<html>

<body>
<form name="f1">
<hl>Even Numbers between 50 to 150</hl>
onMouseOver="chk()"s
<inputtype="button" name="bl" value='Even Numbers"
</form>
</body>
<script type='text/javascript'>
function chk)

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

document. write(i+"<br>");

</script>
</html>
Output:
X
prgSAtol

Even Numbers between 50 to 150


Even Numbers
[Link] Technology (Science) AdvancedlavSaipt
3-58
Write an event driven JavaSeript proam to display odd numbers between 50 to
200.

Ans. :
Coding:
DOCTYPEhtmls
chtmls

<form name="f1">
chl>Odd Numbers between 50 to 200</h1>
<input type="button" name="b1" value=Odd Numbers onCick=chk()'>
k/torm>
k/bodys
script type='text/javascript'>
function chk)

vari;
for(i=51j<=150,i=i+2)

[Link](i+"<brs");

</script>
</html>
Output :
¢ ’ GFle PTS%202622-2asoggheni

200
Odd Numbers between 50 to
event driven JavaScript program to display area of a circle. Accept
10. Write an
radius from the user (area =3.14xrxXr).
Ans.: Coding :
<DOCTYPE html>
html>

body>
<form name="f1">
TPS Information Technology (Science) 3-63
Advanced Javasrip
Enter Radius
<input type='number" name="nl"'><br><br>
|Cinput type="button" name="b1" value="Area of Circle" onClick="area()">
</form>
</body>
<script type="text/javascripe">
function area()
var a,r,p3.14;
|r=parselnt([Link]);
a=p*rr;
lalert("Area of Circle is "+a);

|</script>
</htmlb

Output:
prgi2html

OFileF/TPS%202022-23/Javascript/prg12...
Enter Radus

Area of Circe
TPS Information Technology (Science) Advanced JavaScript
3-64

11. Write an event driven JavaScript program to display area of a rectange r


length and breadth from the user (area = 1xb).
Ans. :

Coding :
eDOCTYPE html>

chtml>

<body>
<form name="f1">

Enter Length
cinputtype='number" name='nl"><br><br>
Enter Breadth
cinput type='number" name="n2"><br><br>
Rectangle" onClick='area()">
<input type="button" name="b1" value-"Area of
</form>

k/body>
<script type="text/javascript'>
function area()

|var l,b,a;
-parselnt([Link]);
bparselnt([Link]);
la=l"b;
alert("Area of Rectangle is "+a);

</script>
</html>

You might also like