0% found this document useful (0 votes)
12 views35 pages

Javascript Programs Notes Word

The document contains a collection of JavaScript programs demonstrating various functionalities such as arithmetic operations, conditional statements, loops, and user input handling. Each program is structured in HTML format and includes scripts for tasks like calculating sums, determining prime numbers, and generating series. The examples illustrate basic programming concepts and can serve as educational resources for learning JavaScript.

Uploaded by

23bcs13796
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)
12 views35 pages

Javascript Programs Notes Word

The document contains a collection of JavaScript programs demonstrating various functionalities such as arithmetic operations, conditional statements, loops, and user input handling. Each program is structured in HTML format and includes scripts for tasks like calculating sums, determining prime numbers, and generating series. The examples illustrate basic programming concepts and can serve as educational resources for learning JavaScript.

Uploaded by

23bcs13796
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

JAVASCRIPT PROGRAMS

JAVASCRIPT
1). <html>
<head>
<title>javascript</title>
</head>
<body>
<script>
[Link]("hello");
</script>
</body>
</html>

WARNING
2). <html>
<head>
<title>warning</title>
</head>
<body>
<script>
alert("warning");
confirm("press okk when confirm");
</script>
</body>
</html>

1
JAVASCRIPT PROGRAMS

SUM
3). <html>
<head>
<title>arithmetic opertor</title>
</head>
<body>
<script>
var a,b,c;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
c=(a+b);
[Link]("value of a is="+a);
[Link]("<br>value of b is="+b);
[Link]("<br>value of c is="+c);
</script>
</body>
</html>

MULTIPLY
4). <html>
<head>
<title>arithmetic opertor</title>
</head>
<body>
<script>
var a,b,c;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
c=(a*b);
[Link]("value of a is="+a);
[Link]("<br>value of b is="+b);
[Link]("<br>value of c is="+c);
</script>
</body>
</html>

2
JAVASCRIPT PROGRAMS

DIVISION
5). <html>
<head>
<title>arithmetic opertor</title>
</head>
<body>
<script>
var a,b,c;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
c=(a/b);
[Link]("value of a is="+a);
[Link]("<br>value of b is="+b);
[Link]("<br>value of c is="+c);
</script>
</body>
</html>

3
JAVASCRIPT PROGRAMS

PERCENTAGE
6.) <html>
<head>
<title>arithmetic opertor</title>
</head>
<body>
<script>
var a,b,c;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
c=(a*b/2);
[Link]("value of a is="+a);
[Link]("<br>value of b is="+b);
[Link]("<br>value of c is="+c);
</script>
</body>
</html>
AREA OF RECTANGLE
7). <html>
<head>
<title>area of rectangle</title>
<head>
<body>
<script>
var b,h,a;
b=parseInt(prompt("enter the base"));
h=parseInt(prompt("enter the height"));
[Link]("base is ="+b);
[Link]("height is ="+h);
a=(b*h);
[Link]("<br>area is="+a);
</script>
</body>
</html>

4
JAVASCRIPT PROGRAMS

CIRCUMFERENCE OF CIRCLE
9). <html>
<head>
<title>circumference</title>
<head>
<body>
<script>
var r,c;
r=parseInt(prompt("enter the radius"));
[Link]("radius is ="+r);
c=(2*3.14*r);
[Link]("<br>circumference is="+c);
</script>
</body>
</html>

5
JAVASCRIPT PROGRAMS

VOLUME OF CUBE

10). <html>
<head>
<title>volume of cube</title>
<head>
<body>
<script>
var a,v;
a=parseInt(prompt("enter the side"));
v=(a*a*a);
[Link]("side is ="+a);
[Link]("<br>volume is="+v);
</script>
</body>
</html>
VOLUME OF CUBOID
11). <html>
<head>
<title>volume of cubiod</title>
<head>
<body>
<script>
var l,b,h,v;
l=parseInt(prompt("enter the length"));
b=parseInt(prompt("enter the breadth"));
h=parseInt(prompt("enter the height"));
v=l*b*h;
[Link]("length is ="+l);
[Link]("<br>breadth is ="+b);
[Link]("<br>height is ="+h);
[Link]("<br>volume is="+v);
</script>
</body>
</html>

6
JAVASCRIPT PROGRAMS

VOLUME OF CYLINDER

12). <html>
<head>
<title>volume of cylinder</title>
<head>
<body>
<script>
var a,c;
r=parseInt(prompt("enter the radius"));
h=parseInt(prompt("enter the height"));
[Link]("radius is ="+r);
[Link]("height is ="+h);
v=(3.14*r*r*h);
[Link]("<br>volume is="+v);
</script>
</body>
</html>
VOLUME OF CONE
13). <html>
<head>
<title>volume of cone</title>
<head>
<body>
<script>
var a,c;
r=parseInt(prompt("enter the radius"));
h=parseInt(prompt("enter the height"));
[Link]("radius is ="+r);
[Link]("height is ="+h);
v=(1/3*3.14*r*r*h);
[Link]("<br>volume is="+v);
</script>
</body>
</html>

7
JAVASCRIPT PROGRAMS

AREA OF SQUARE
15.) <html>
<head>
<title>area of squre</title>
<head>
<body>
<script>
var h,a;
h=parseInt(prompt("enter the height"));
[Link]("height is ="+h);
a=(h*h);
[Link]("<br>area is="+a);
</script>
</body>
</html>

8
JAVASCRIPT PROGRAMS

VOLUME OF SPHERE
16.) <html>
<head>
<title>volume of sphere</title>
<head>
<body>
<script>
var a,c;
r=parseInt(prompt("enter the radius"));
[Link]("radius is ="+r);
v=(4/3*3.14*r*r*r);
[Link]("<br>volume is="+v);
</script>
</body>
</html>
ODD - EVEN
17). <html>
<head>
<title>conditional operator</title>
</head>
<body>
<script>
var a;
a=parseInt(prompt("enter the value of a"));
[Link]("value of a is="+a);
if(a%2!=0)
{
[Link]("<br>a is odd number="+a);
}
else
{
[Link]("<br>a is even number="+a);
}
</script>
</body>
</html>

9
JAVASCRIPT PROGRAMS

POSITIVE - NEGATIVE
18). <html>
<head>
<title>conditional operator</title>
</head>
<body>
<script>
var a;
a=parseInt(prompt("enter the value of a"));
[Link]("value of a is="+a);
if(a>0)
{
[Link]("<br>a is positive number="+a);
}
else
{
[Link]("<br>a is negative number="+a);
}
</script>
</body>
</html>

10
JAVASCRIPT PROGRAMS

PRIME NUMBER
19). <html>
<head>
<title>prime number</title>
</head>
<body>
<script>
var prime=0,half,num,i;
num=parseInt(prompt("enter the number"));
[Link]("number is="+num);
half=num/2;

for(i=2;i<=half;i++)
{
if(num%i==0)
{
prime=1;
break;
}
}

if(prime==1)
{
[Link]("<br>this is not prime number="+num);
}
else
{
[Link]("<br>this is prime number="+num);
}
</script> </body>
</html>

11
JAVASCRIPT PROGRAMS

SIMPLE INTEREST
20). <html>
<head>
<title>simple interest</title>
</head>
<body>
<script>
var p,r,t,si;
p=parseInt(prompt("enter the principle"));
r=parseInt(prompt("enter the rate"));
t=parseInt(prompt("enter the time"));
si=(p*r*t)/100
[Link]("principle is="+p);
[Link]("<br>rate is="+r);
[Link]("<br>time is="+t);
[Link]("<br>SI is="+si);
</script>
</body>
</html>
GREATER THAN (AB)
21.) <html>
<head>
<title>greater than</title>
</head>
<body>
<script>
var a,b;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
[Link]("value of a is="+a);
[Link]("<br>value of b is="+b);
if(a>b)
{
[Link]("<br>a is greater="+a);
}
else
{
[Link]("<br>b is greater="+b);
}
</script>
</body>
</html>

12
JAVASCRIPT PROGRAMS

GREATER THAN (ABC)


22). <html>
<head>
<title>greater than</title>
</head>
<body>
<script>
var a,b,c;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
c=parseInt(prompt("enter the value of c"));
[Link]("value of a is="+a);
[Link]("<br>value of b is="+b);
[Link]("<br>value of c is="+c);
if(a>b && a>c)
{
[Link]("<br>a is greater="+a);
}
else if(b>a && b>c)
{
[Link]("<br>b is greater="+b);
}
else
{
[Link]("<br>c is greater="+c);
}
</script>
</body>
</html>

13
JAVASCRIPT PROGRAMS

CONTINUE STATEMENT
23). <html>
<head>
<title>break satement</title>
</head>
<body>
<script>
var a;
for(a=1;a<=10;a++)
{
if(a==7)
{
continue;
}
[Link]("<br>"+a);
}
</script>
</body>
</html>
BREAK STATEMENT
24). <html>
<head>
<title>break satement</title>
</head>
<body>
<script>
var a;
for(a=1;a<=10;a++)
{
if(a==7)
{
break;
}
[Link]("<br>"+a);
}
</script>
</body>
</html>

14
JAVASCRIPT PROGRAMS

VOWEL OR NOT
25.) <html>
<head>
<title>break satement</title>
</head>
<body>
<script>
var ch;
ch=prompt("enter the text");
[Link]("text is ="+ch);
if(ch=="a"||ch=="e"||ch=="o"||ch=="i"||ch=="u")
{
[Link]("<br>this is vowel="+ch);
}
else
{
[Link]("<br>this is not vowel="+ch);
}
</script>
</body>
</html>
FOR LOOP
26.) <html>
<head>
<title>for loop</title>
</head>
<body>
<script>
var a;
for(a=1;a<=10;a++)
{
[Link]("<br>"+a);
}
</script>
</body>
</html>

15
JAVASCRIPT PROGRAMS

REVERSE LOOP

27.) <html>
<head>
<title>for loop</title>
</head>
<body>
<script>
var a;
for(a=10;a>=1;a--)
{
[Link]("<br>"+a);
}
</script>
</body>
</html>
FULL TICKET
28.) <html>
<head>
<title>ticket</title>
</head>
<body>
<script>
var age;
age=parseInt(prompt("enter the age"));
if(age>60 && age<14)
{
[Link]("half ticket="+age);
}
else
{
[Link]("full ticket="+age);
}
</script>
</body>
</html>

16
JAVASCRIPT PROGRAMS

LEAP YEAR
29.) <html>
<head>
<title>leap year</title>
</head>
<body>
<script>
var year;
year=parseInt(prompt("enter the year"));
if(year%4==0 && year%100!=0 || year%400==0)
{
[Link]("this is leap year="+year);
}
else
{
[Link]("<br>this is not leap year="+year);
}
</script>
</body>
</html>
SUM OF NATURAL NUMBER
30.) <html>
<head>
<title>natural number</title>
</head>
<body>
<script>
var i,n,sum=0;
i=parseInt(prompt("enter the value of i"));
[Link]("number is="+i);
for(n=1;n<=i;n++)
{
[Link]("<br>"+n);
sum=sum+n;
}
[Link]("<br>sum is"+sum);
</script>
</body>
</html>

17
JAVASCRIPT PROGRAMS

SUM OF EVEN NATURAL NUMBER


31.) <html>
<head>
<title>natural number</title>
</head>
<body>
<script>
var i,n,sum=0;
i=parseInt(prompt("enter the value of i"));
[Link]("number is="+i);
for(n=1;n<=i;n++)
{
if(n%2==0)
{
[Link]("<br>"+n);
sum=sum+n;
}
}
[Link]("<br>sum is"+sum);
</script>
</body>
</html>
SUM OF ODD NATURAL NUMBER
32.) <html>
<head>
<title>natural number</title>
</head>
<body>
<script>
var i,n,sum=0;
i=parseInt(prompt("enter the value of i"));
[Link]("number is="+i);
for(n=1;n<=i;n++)
{
if(n%2!=0)
{
[Link]("<br>"+n);
sum=sum+n;
}
}
[Link]("<br>sum is"+sum);
</script></body></html>

18
JAVASCRIPT PROGRAMS

FACTORIAL SERIES
33.) <html>
<head>
<title>factroial series</title>
</head>
<body>
<script>
var fact=1,a,b;
a=parseInt(prompt("enter the value of a"));
[Link]("value of a is="+a);
for(b=1;b<=a;b++)
{
fact=fact*b;
[Link]("<br>fact is="+fact);
}
</script>
</body>
</html>
FACTORIAL SERIES 02
34.) <html>
<head>
<title>factorial series</title>
</head>
<body>
<script>
var i,j,k;
i=parseInt(prompt("enter the value of i"));
[Link]("value of i is ="+i);
for(j=1;j<=10;j++)
{
k=i*j;
[Link]("<br>table is ="+k);
}
</script></body></html>

19
JAVASCRIPT PROGRAMS

FABONACCI SERIES
35.) <html>
<head>
<title>fabonacci series</title>
</head>
<body>
<script>
var a,b,c=0,d=1,e;
a=parseInt(prompt("enter the value"));
[Link]("value of a is="+a);
for(b=1;b<=a;b++)
{
e=c+d;
c=d;
d=e;
[Link]("<br>Answer is="+e);
}
</script> </body>
</html>
REVERSE OF A NUMBER
36.) <html>
<head>
<title>rev of a number</title>
</head>
<body>
<script>
var rev=0,digit,num;
num=parseInt(prompt("enter the number"));
[Link]("value is="+num);
while(num>0)
{
digit=num%10;
rev=rev*10+digit;
num=parseInt(num/10);
[Link]("<br>rev is="+rev);
}
</script></body></html>

20
JAVASCRIPT PROGRAMS

REVERSE OF A NUMBER
37.) <html>
<head>
<title>rev of a number</title>
</head>
<body>
<script>
var rev=0,digit,num;
num=parseInt(prompt("enter the number"));
[Link]("value is="+num);
while(num>0)
{
digit=num%10;
rev=rev*10+digit;
num=parseInt(num);
[Link]("<br>rev is="+rev);
}
</script></body></html>
SWITCH CASE
38.) <html>
<head>
<title>switch case </title>
</head>
<body>
<script>
var a;
a=parseInt(prompt("enter the case"));
[Link]("case is="+a);
switch(a)
{
case 1:
[Link]("<br>monday");
break;

case 2:
[Link]("<br>tuesday");
break;

default:
[Link]("<br>invalid case");
}
</script></body></html>

21
JAVASCRIPT PROGRAMS

SWITCH CASE 02
39.) <html>
<head>
<title>switch case </title>
</head>
<body>
<script>
var a,b,c,d;
a=parseInt(prompt("enter the case"));
[Link]("case is="+a);
switch(a)
{
case 1:
b=parseInt(prompt("enter the value of b"));
c=parseInt(prompt("enter the value of c"));
d=b+c;
[Link]("<br>sum is="+d);
break;

case 2:
[Link]("<br>tuesday");
break;

default:
[Link]("<br>invalid case");
}
</script>
</body>
</html>

22
JAVASCRIPT PROGRAMS

PALLIDROME OF A NUMBER
40.) <html>
<head>
<title>palindrime of a number</title>
</head>
<body>
<script>
var rev=0,digit,num,n;
num=parseInt(prompt("enter the number"));
[Link]("value is="+num);
n=num;
while(num>0)
{
digit=num%10;
rev=rev*10+digit;
num=parseInt(num/10);
[Link]("<br>rev is="+rev);
}
if(n=rev)
{
[Link]("<br>this is pallindrome="+rev);
}
else
{
[Link]("<br>this is not pallindrome="+rev);
}
</script></body></html>

23
JAVASCRIPT PROGRAMS

PALLIDROME OF NUMBER 02
41). <html><head>
<title>pallindrome</title>
</head><body><script>
var rev=0,digit,num,n;
num=parseInt(prompt("enter the value of num"));
[Link]("num is="+num);
n=num;
while(num>0)
{
digit=num%10;
rev=rev*10+digit;
num=parseInt(num/10);
}
[Link]("<br>rev is="+rev);

if(n==rev)
{
[Link]("<br>this is pallindrome="+rev);
}
else
{
[Link]("<br>this is not pallindrome="+rev);
}
</script></body></html>

24
JAVASCRIPT PROGRAMS

STAR PATTERN
42.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var a,b;
a=parseInt(prompt("enter the value of a"));
b=parseInt(prompt("enter the value of b"));
[Link]("before swapping:-");
[Link]("<br>value of a is="+a);
[Link]("<br>value of b is="+b);
a=a+b;
b=a-b;
a=a-b;
[Link]("<br>after swapping:-");
[Link]("<br>value of a is="+a);
[Link]("<br>value of b is="+b);
</script>
</body>
</html>
STAR PATTERN 02
43.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
[Link](+i);
}
[Link]("<br>");
}
</script>
</body>
</html>

25
JAVASCRIPT PROGRAMS

STAR PATTERN 03
44.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
[Link](+j);
}
[Link]("<br>");
}
</script>
</body>
</html>
STAR PATTERN -04
45.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
[Link](" * ");
}
[Link]("<br>");
}
</script>
</body>
</html>

26
JAVASCRIPT PROGRAMS

STAR PATTERN 05
46.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var i,j;
for(i=10;i>=1;i--)
{
for(j=1;j<=i;j++)
{
[Link](+i);
}
[Link]("<br>");
}
</script>
</body>
</html>
STAR PATTERN 06
47.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var i,j;
for(i=10;i>=1;i--)
{
for(j=1;j<=i;j++)
{
[Link]("&");
}
[Link]("<br>");
}
</script>
</body>
</html>

27
JAVASCRIPT PROGRAMS

STAR PATTERN 07
48.) <html>
<head>
<title>star pattern</title>
</head>
<body>
<script>
var i,j;
for(i=10;i>=1;i--)
{
for(j=1;j<=i;j++)
{
[Link](" * ");
}
[Link]("<br>");
}
</script>
</body>
</html>
ARRAY
49.) <html>
<head>
<title>Array</title>
</head>
<body>
<script>
var a=new Array(50),i;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the value of a[i]"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}
</script></body></html>

28
JAVASCRIPT PROGRAMS

ARRAY SUM
50.) <html>
<head>
<title>Array</title>
</head>
<body>
<script>
var a=new Array(50),i,sum=0;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the value of a[i]"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
sum=sum+a[i];
}
[Link]("<br>sum is ="+sum);
</script></body></html>

29
JAVASCRIPT PROGRAMS

ARRAY ASC-DEC.
51.) <html>
<head>
<title>asc.-dec.</title>
</head>
<body>
<script>
var a=new Array(50),i,j,k;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the number"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}

for(i=1;i<=5;i++)
{
for(j=1+i;j<=5;j++)
{
if(a[i]>a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
}
[Link]("<br>Order is:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}
</script></body></html>

30
JAVASCRIPT PROGRAMS

ARRAY ODD
52.) <html>
<head>
<title>Array</title>
</head>
<body>
<script>
var a=new Array(50),i;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the number"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}
[Link](" <br>odd Elements are:-");
for(i=1;i<=5;i++)
{
if(a[i]%2==0)
{
[Link]("<br>"+a[i]);

}
}
</script></body></html>

31
JAVASCRIPT PROGRAMS

ARRAY ASC-DEC.
53.) <html>
<head>
<title>asc.-dec.</title>
</head>
<body>
<script>
var a=new Array(50),i,j,k;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the number"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}

for(i=1;i<=5;i++)
{
for(j=1+i;j<=5;j++)
{
if(a[i]<a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
}
[Link]("<br>Order is:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}
</script></body></html>

32
JAVASCRIPT PROGRAMS

ARRAY EVEN
54.) <html>
<head>
<title>Array</title>
</head>
<body>
<script>
var a=new Array(50),i;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the number"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}
[Link](" <br>even Elements are:-");
for(i=1;i<=5;i++)
{
if(a[i]%2==0)
{
[Link]("<br>"+a[i]);

}
}
</script></body></html>

33
JAVASCRIPT PROGRAMS

ARRAY EVEN SUM


55.) <html>
<head>
<title>Array</title>
</head>
<body>
<script>
var a=new Array(50),i,sum=0;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the number"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}
[Link](" <br>even Elements are:-");
for(i=1;i<=5;i++)
{
if(a[i]%2==0)
{
[Link]("<br>"+a[i]);
sum=sum+a[i];
}
}
[Link]("<br>sum is ="+sum);
</script></body></html>

34
JAVASCRIPT PROGRAMS

ARRAY MAX-MIN
56.) <html>
<head>
<title>min.-max.</title>
</head>
<body>
<script>
var a=new Array(50),i,max;
for(i=1;i<=5;i++)
{
a[i]=parseInt(prompt("enter the number"));
}

[Link]("Elements are:-");
for(i=1;i<=5;i++)
{
[Link]("<br>"+a[i]);
}

max=a[1];

for(i=1;i<=5;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
[Link]("<br>max is="+max);
</script></body></html>

35

You might also like