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

Advanced Javascript Board Exam Question

The document contains multiple JavaScript programs demonstrating various functionalities such as addition of two numbers, calculating factorials, checking for odd/even numbers, finding prime numbers, and generating number sequences. Each program is presented in HTML format with appropriate event handling techniques like onmouseover and onclick. The examples serve as practical applications for learning JavaScript programming concepts.

Uploaded by

bmwx7201
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)
7 views

Advanced Javascript Board Exam Question

The document contains multiple JavaScript programs demonstrating various functionalities such as addition of two numbers, calculating factorials, checking for odd/even numbers, finding prime numbers, and generating number sequences. Each program is presented in HTML format with appropriate event handling techniques like onmouseover and onclick. The examples serve as practical applications for learning JavaScript programming concepts.

Uploaded by

bmwx7201
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/ 6

Advanced Javascript

//write a javascript program display addition of two number using onmouseover event//

<html>
<script language="javascript">
function sum()
{
var a,b,s;
a=parseInt(form1.t1.value);
b=parseInt(form1.t2.value);
s=a+b;
alert("addition is"+s);
}
</script>
<body>
<form name="form1">
Enter first number:
<input type="text"name="t1"><br>
Enter second number:
<input type="text"name="t2"><br>
<input type="button"name="b1"value="addition"onMouseOver="sum()">
</form>
</body>
</html>

//write a javascript program print factorial number//


<html>
<script type="text/javascript">
var n,i,f=1;
n=prompt("Enter a number");
for(i=n;i>=1;i--)
{
f=f*i;
}
document.write("<br>Factorial is"+f);
</script>
</html>

//write a javascript programe to print factorical number using onclick event//

<html>
<head>
</head>
<body style="text-align:center;font-size:20px;">
<h1>Factorial number</h1>
Enter a number:<input id="num">
<br><br>
<button onClick="fact()">factorial</button>
<p id="res"></p>
<script>
function fact()
{
var i,num,f;
f=1;
num=document.getElementById("num").value;
for(i=1;i<=num;i++)
{
f=f*i;
}
i=i-1;
document.getElementById("res").innerHTML="the factorial of the number"+i+"is:"+f;
}
</script>
</body>
</html>

//To accept two integers and display larger number of them//


<html>
<head>
<title> greater two number</title>
</head>
<script language="javascript">
var a,b;
a=prompt("enter a number");
b=prompt("enter b number");
if(a>b)
document.write("First number is greater than second number");
else
document.write("second number is greater than first number");
</script>
</html>

//To accept string and calculate its length//


<html>
<head>
<title>string</title>
</head>
<body>
<script language="javascript">
var a;
a=prompt("Enter string");
alert("length of string:"+a.length);
</script>
</body>
</html>
//write a javascript program to print table//
<html>
<head>
<title>Table-I</title>
<script type="text/javascript">
var i,a;
a=parseInt(prompt("enter number"));
for(i=1;i<=10;i++)
{
document.write(a*i + "<br/>");
}

</script></head>
</html>

//write a javascript programe to check number is odd or even//


<html>
<body>
<form name="frm1">
Enter a number
<input type="number"name="t1"><br><br>
<input type="button"name="b1"value="odd Even"onClick="even()">
</form>
</body>
<script type="text/javascript">
function even()
{
var a;
a=frm1.t1.value;
if(a%2==0)
alert("Number is even");
else
alert("Number is odd");
}
</script>
</html>

//write a javascript program to print prime number//


<html>
<html><head><title>Prime number</title>
<script type="text/javascript">
function display()
{
var a,ans;
a=parseInt(form1.t1.value);
ans=1;
for(i=2;i<a;i++)
{
if(a%i==0)
{
ans=0;
break;
}
}
if(ans==1)
alert("Number is prime");
else
alert("Number is not prime");
}
</script></head>
<body>
<h1 align="center"> Program to check number is prime or not </h1>
<form name="form1" style="text-align:center">
Enter your Number (Greater than one):-<input type="text" name="t1"> <br>
<input type="button" value="check Prime number"onClick="display()">
</body>
</html>

//write a code print number from 1 to 10//


<html>
<head>
<title> print 1 to 10 number</title>
</head>
<body>
<script language="javascript">
var i;
document.write("print number from 1 to 10 number");
for(i=1;i<=10;i++)
{
document.write("<br>"+i);
}
</script>
</body>
</html>

//write a javascript code print all odd numbers from 50 to 100//


<html>
<head>
<title>print all odd numbers from 50 to 100</title>
</head> <body>
<script language="javascript">
var i;
document.write("odd numbers from 50 to 100");
for(i=50;i<=100;i++)
{
if(i%2!=0)
document.write("<br>"+i);
}
</script>
</body>
</html>
// write a javascript program print 10 to 50 even number//

<html>
<script type="text/javascript">
var i;
document.write("print number form 10 to 50");
for(i=10;i<=50;i=i+2)
{
document.write("<br>"+i);
}
</script>
</html>

//write event driven javascript program to take number as user input and
find the square root//
<html>
<body>
<script>
function display()
{
var x=document.getElementById("num").value;
document.getElementById("result").innerHTML=Math.sqrt(x);
}
</script>
<form>
Enter a number: <input type="text" id="num">
<input type="button" onclick="display()" value="submit">
</form>
<p>
<span id="result"></span></p>

</body>
</html>

//To accept number and display square of it.//<br>

<html>
<head>
<title>check number</title></head>
<body>
<script language="javascript">
var a, squ;
a=prompt("enter number");
squ=a*a;
document.write("display square of:"+squ);
</script>
</body>
</html>
//write a code print sum of 50 natural number//
<html>
<head>
<title>print sum of 50 natural number</title>
</head>
<body>
<script language="javascript">
var i,sum=0;
document.write("sum of numbers from 1 to 50");
for(i=1;i<=50;i++)
{
document.write("<br>"+i);
sum=sum+i;
}
document.write("sum"+sum);
</script>
</body>
</html>

//writea javascript program to print table using event handling//


<html>
<head>
<title>Table-I</title>
<script type="text/javascript">
function display()
{
var i,a;
a=frm1.t1.value;
for(i=1;i<=10;i++)
{
document.write("<br>"+i*a);
}
}
</script>
</head>
<body>
<form name="frm1">
Enter number to display table:-
<input type="text"name="t1">
<input type="button"value="Display Table"onClick="display()">
</body>
</html>

You might also like