0% found this document useful (0 votes)
8 views2 pages

JavaScript Programs for Basic Calculations

The document contains code snippets for several JavaScript programs: 1) A program to calculate the total and average of 5 test marks. 2) A program that swaps the values of two variables. 3) A program to calculate HRA, DA, and total salary based on basic salary. 4) Programs to determine if a number is even or odd, greater of two numbers, and if a person is major or minor based on their age. 5) A program to calculate HRA and DA at different rates depending on if basic salary is above or below 15,000. 6) A program to determine the greatest of three numbers. 7) A program to determine division (1st
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

JavaScript Programs for Basic Calculations

The document contains code snippets for several JavaScript programs: 1) A program to calculate the total and average of 5 test marks. 2) A program that swaps the values of two variables. 3) A program to calculate HRA, DA, and total salary based on basic salary. 4) Programs to determine if a number is even or odd, greater of two numbers, and if a person is major or minor based on their age. 5) A program to calculate HRA and DA at different rates depending on if basic salary is above or below 15,000. 6) A program to determine the greatest of three numbers. 7) A program to determine division (1st
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//Program to find average and total marks

var m1=45,m2=55,m3=65,m4=75,m5=85,total,avg;
total=m1+m2+m3+m4+m5;
avg=total/5;
[Link]("total="+total+"<br/>");
[Link]("Average="+avg+"<br/>");

//Swapping
var a=10,b=20,t;
[Link]("a= "+a+"b= "+b+" before swapping <br/>");
t=a;
a=b;
b=t;
[Link]("a= "+a+"b= "+b+" after swapping <br/>");

//Program to find hra,da and ts


var bs=2355,hra,da,ts;
hra=.40*bs;
da=.35*bs;
ts=bs+hra+da;
[Link]("hra="+hra+"<br/>");
[Link]("da="+da+"<br/>");
[Link]("ts="+ts+"<br/>");

//Program to find age major or minor


var a=15;
if(a>=18)
[Link]("Major");
else
[Link]("Minor");

//Program to find greatest of two numbers


var a=15,b=24;
if(a>b)
[Link]("A is greatest");
else
[Link]("B is greatest");

//Program to find even or odd


var a=15;
if(a%2==0)
[Link]("Even");
else
[Link]("Odd");

//Program to check if basic salary is greater then 15000

var bs=20000,hra,da,ts;
if(bs>15000)
{
hra=.40*bs;
da=.35*bs;
}
else
{
hra=.35*bs;
da=.30*bs;
}
ts=hra+da+bs;
[Link]("hra="+hra+"<br/>");
[Link]("da="+da+"<br/>");
[Link]("ts="+ts+"<br/>");

//Greatest of three numbers

var a=10,b=20,c=30;
if(a>b)
if(a>c)
[Link]("A is greatest");
else
[Link]("C is greatest");
else
if(b>c)
[Link]("B is greatest")
else
[Link]("C is greatest");

//Program to find division based on percentage

var p=45;
if(p>=60)
[Link]("First Division");
else
if(p>=50)
[Link]("2nd Division");
else
if(p>=40)
[Link]("3rd Division");
else
[Link]("Fail");

You might also like