Write an event driven JavaScript program to display square of accepted number.
<!doctype html>
<html>
<head><title>square of a number</title>
<script type="text/javascript">
function square()
{
var n,s
n=parseInt(prompt("enter a number"));
s=n*n;
[Link]("square of "+n+"="+s);
}
</script>
</head>
<body>
<h3>calculating square of a number</h3>
<input type="button" value="square" onclick="square()">
</body>
</html>
Write an event driven JavaScript program to display double of accepted number.
<!doctype html>
<html>
<head><title>double of a number</title>
<script type="text/javascript">
function double()
{
var n,d;
n=parseInt(prompt("enter a number"));
d=n+n;
[Link]("double of "+n+" is "+d);
}
</script>
</head>
<body>
<h3>displaying double of a number</h3>
<input type="button" value="double" onclick="double()">
</body>
</html>
Write an event driven JavaScript program to display table of accepted number.
<!doctype html>
<html>
<head><title>table</title>
<script type="text/javascript">
function table()
{
var n,i
n=parseInt(prompt("enter a number"));
for(i=1;i<=10;i++)
{
[Link](n*i+"<br>");
}
}
</script>
</head>
<body>
<h3>displaying table of a number</h3>
<input type="button" value="table" onclick="table()">
</body>
</html>
Write an event driven JavaScript program to display table of 7.
<!doctype html>
<html>
<head><title>table</title>
<script type="text/javascript">
function table()
{
var n=7,i
for(i=1;i<=10;i++)
{
[Link](n*i+"<br>");
}
}
</script>
</head>
<body>
<h3>displaying table of 7</h3>
<input type="button" value="table" onclick="table()">
</body>
</html>
Write an event driven JavaScript program to find factorial of 5.
<!doctype html>
<html>
<head><title>factorial</title>
<script type="text/javascript">
function facto()
{
var n,i,fact=1;
for(n=5;n>=1;n--)
{
fact=fact*n;
}
[Link]("factorial of 5 is:"+fact);
}
</script>
</head>
<body>
<h3>displaying facorial of 5</h3>
<input type="button" value="factorial" onclick="facto()">
</body></html>
Write an event driven JavaScript program to find factorial of 5 when mouse is moved on the button.
<!doctype html>
<html>
<head><title>factorial</title>
<script type="text/javascript">
function facto()
{
var n,i,fact=1;
for(n=5;n>=1;n--)
{
fact=fact*n;
}
[Link]("factorial of 5 is:"+fact);
}
</script>
</head>
<body>
<h3>displaying facorial of 5</h3>
<input type="button" value="factorial" onmousemove="facto()">
</body></html>
Write an event driven JavaScript program to find factorial of accepted number.
<!doctype html>
<html>
<head><title>factorial</title>
<script type="text/javascript">
function facto()
{
var n,i,fact=1;
n=parseInt(prompt("enter a number"));
for(var n1=n;n1>=1;n1--)
{
fact=fact*n1;
}
[Link]("factorial of "+n+" is:"+fact);
}
</script>
</head>
<body>
<h3>calculating facorial of a number</h3>
<input type="button" value="factorial" onclick="facto()">
</body></html>
Write an event driven JavaScript program to call a function after 2000 milliseconds and display text
“hello”.
<!doctype html>
<html>
<head><title>JavaScript</title>
<script type="text/JavaScript">
function f1()
{
[Link](f2(),2000);
}
function f2()
{
alert("hello");
}
</script>
</head>
<body>
<h3>displaying message</h3>
<input type="button" value="factorial" onclick="f1()">
</body></html>
Write an event driven JavaScript program to display whether accepted number is even or odd.
<!doctype html>
<html>
<head><title>odd even</title>
<script type="text/javascript">
function check()
{
var n;
n=parseInt(prompt("enter a number"));
if(n%2==0)
alert("number is even");
else
alert("number is odd");
}
</script>
</head>
<body>
<h3>checking a number for even odd</h3>
<input type="button" value="odd/even" onclick="check()">
</body></html>
Write an event driven JavaScript program to find sum of first 20 natural numbers.(i.e 1 to 20)
<!doctype html>
<html>
<head><title>natural numbers sum</title>
<script type="text/javascript">
function sum()
{
var sum=0;
for(var i=1;i<=20;i++)
{
sum=sum+i;
}
[Link]("sum of natural numbers 1 to 20 is "+sum);
}
</script>
</head>
<body>
<h3>calculating sum of natural numbers 1 to 20</h3>
<input type="button" value="sum" onclick="sum()">
</body></html>
Write an 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>javascript program</title>
<script type="text/javascript">
function cal()
{
var base, height,area;
base=parseInt(prompt("enter base value"));
height=parseInt(prompt("enter height value"));
area=0.5*base*height;
[Link]("area of triangle is "+area);
}
</script>
</head>
<body>
<h3>calculate area of traingle</h3>
<input type="button" value="area" onclick="cal()">
</body></html>
Write an event driven JavaScript program to display even numbers between 50 to 100.
<!doctype html>
<html>
<head><title>even numbers</title>
<script type="text/javascript">
function evennos()
{
var n;
for(n=50;n<=100;n++)
if(n%2==0)
{
[Link](n+"<br>");
}
}
</script>
</head>
<body>
<h3>even numbers between 50 to 100</h3>
<input type="button" value="evennos" onclick="evennos()">
</body></html>