You are on page 1of 43

PROGRAM 1 AIM: To add two numbers (dynamic program) <html> <body bgcolor="pink"> <font color="green" size=15> <b> <script

language="javascript"> var a,b,ad; a=parseInt(prompt("please enter Ist number to be added")); b=parseInt(prompt("please enter 2nd number to be added")); ad=a+b; document.write("when we add "+a); document.write(" to "+b); document.write(" ,the result is "+ad); </script> </b> </font> </body> </html>

1|Page

2|Page

3|Page

PROGRAM 2 AIM: To subtract two numbers (dynamic program) <html> <body bgcolor="pink"> <font color="green" size=15> <b> <script language="javascript"> var a,b,s; a=parseInt(prompt("please enter the number to be subtracted")); b=parseInt(prompt("please enter the number from which you want the first number to be subtracted")); s=b-a; document.write("when we subtract "+a); document.write(" from "+b); document.write(" ,the result is "+s); </script> </b> </font> </body> </html>

4|Page

5|Page

6|Page

PROGRAM 3 AIM: To multiply two numbers (dynamic program) <html> <body bgcolor="green"> <font size="15"> <script language="javascript"> var a,b,m; a=parseInt(prompt("please enter Ist number")); b=parseInt(prompt("please enter 2nd number")); m=a*b; document.write("when we multiply "+a); document.write(" by "+b); document.write(" ,the result is "+m); </script> </font> </body> </html>

7|Page

8|Page

9|Page

PROGRAM 4 AIM: To divide two numbers (dynamic program) <html> <body bgcolor="orange"> <font color="green" size="15"> <b> <script language="javascript"> var a,b,d; a=parseInt(prompt("please enter the number to be divided")); b=parseInt(prompt("please enter the number by which you want to divide the first number")); d=a/b; document.write("when we divide "+a); document.write(" by "+b); document.write(" ,<br>the result is "+d); </script> </b> </font> </body> </html>

10 | P a g e

11 | P a g e

12 | P a g e

PROGRAM 5 AIM: To find the greatest of three numbers <html> <body> <font size="15"> <script language="javascript"> var a,b,c,g; a=parseInt(prompt("please enter Ist number")); b=parseInt(prompt("please enter 2nd number")); c=parseInt(prompt("please enter 3rd number")); if(a>=b) g=a; else g=b; if(g>=c) {document.write("Out of " +a); document.write(" , " +b); document.write(" and " +c); document.write(" ; the greatest number is " +g);} else {document.write("Out of " +a); document.write(" , " +b); document.write(" and " +c); document.write(" ; the greatest number is " +c);} </script> </body> </html>

13 | P a g e

14 | P a g e

15 | P a g e

PROGRAM 6 AIM: To find the greatest of three numbers (using nested if-else) <html> <body bgcolor> <font size="15"> <script language="javascript"> var a,b,c,g; a=parseInt(prompt("please enter Ist number")); b=parseInt(prompt("please enter 2nd number")); c=parseInt(prompt("please enter 3rd number")); if(a>=b) {if(a>=c) document.write("greatest of the three numbers is " +a)} else { if(b>=c) document.write("greatest of the three numbers is " +b) else document.write("greatest of the three numbers is " +c) } </script> </body> </html>

16 | P a g e

17 | P a g e

18 | P a g e

PROGRAM 7 AIM: To grade students using If-else statement, conditional && operator <html> <head> <title>Javascript</title> </head> <body> <font size="15"> <script language="javascript"> var num1,num2,num3; num1=parseInt(prompt("Please enter the marks of ASM ","")); num2=parseInt(prompt("Please enter the marks of FSM ","")); num3=parseInt(prompt("Please enter the marks of MR ","")); total = num1+num2+num3; per = total/300*100; if(per >=70) document.write("Grade of the Student is A+"); else if( (per>=60) && (per<70)) document.write("Grade of the Student is A"); else if( (per>=50) && (per<60) ) document.write("Grade of the Student is B"); else if( (per>=40) && (per<50) ) document.write("Grade of the Student is C"); else document.write("Sorry to say, but the Student is Fail"); </script> </body> </html>

19 | P a g e

20 | P a g e

21 | P a g e

PROGRAM 8 AIM: To swap two numbers using third number <html> <head> <title>Javascript</title> </head> <body> <font size="15"> <script language="javascript"> var num1,num2,temp; num1=parseInt(prompt("Enter any integer number ","")); num2=parseInt(prompt("Enter any integer number ",""));

document.write("Value of first number before swap is "+num1); document.write("<br>Value of second number before swap is "+num2);

temp=num1; num1=num2; num2=temp;

document.write("<br>Value of first number after swap is "+num1); document.write("<br>Value of second number after swap is "+num2); </script> </font> </body> </html>

22 | P a g e

23 | P a g e

24 | P a g e

PROGRAM 9 AIM: To swap two numbers without using third number <html> <head> <title>Javascript</title> </head> <body> <font size="15"> <script language="javascript">

var a,b; a=parseInt(prompt("Enter any integer number ","")); b=parseInt(prompt("Enter any integer number ",""));

document.write("Value of first number before swap is "+a); document.write("<br>Value of second number before swap is "+b);

a=a+b; b=a-b; a=a-b;

document.write("<br>Value of first number after swap is "+a); document.write("<br>Value of second number after swap is "+b); </script> </font> </body> </html>

25 | P a g e

26 | P a g e

27 | P a g e

PROGRAM 10 AIM: To choose out of the various arithmetic operations <html> <head> <title>Javascript</title></head> <body><font size="15"> 1 Press A/a for addition<br> 2 Press M/m for multiplication<br> 3 Press S/s for subtraction<br> 4 Press D/d for division<hr width="100% size="15%" color="green"><br><br> <script language="javascript"> var ch,a,b,c; ch=prompt("Please Enter your choice ",""); a=parseInt(prompt("Enter any number ","") ) ; b=parseInt(prompt("Enter any number ","") ) ; if( (ch=='A') || (ch=='a') ) { c=a+b; document.write("when we add "+a); document.write(" to "+b); document.write(" ,the result is "+c);

} else if( (ch=='M') || (ch=='m') ) { c=a*b; document.write("when we multiply "+a); document.write(" by "+b);

28 | P a g e

document.write(" ,the result is "+c);

} else if( (ch=='S') || (ch=='s') ) { c=a-b; document.write("when we subtract "+a); document.write(" from "+b); document.write(" ,the result is "+c);

} else if( (ch=='D') || (ch=='d') ) { c=a/b; document.write("when we divide "+a); document.write(" by "+b); document.write(" ,<br>the result is "+d);

} else { document.write("WRONG KEY PRESSED"); } </script> </font> </body> </html>

29 | P a g e

30 | P a g e

31 | P a g e

PROGRAM 11 AIM: To find out the number of even numbers between the two numbers & their sum using While Loop <html> <head> <title>Javascript</title> </head> <body><font size="15"> <script language="javascript"> var a,i,n,count=0,sum=0; i=parseInt(prompt("Please Enter the start value ")); n=parseInt(prompt("Please Enter the last value ")); a=i; while(i<=n) { if(i%2==0) { document.write(i+" , "); count++; sum=sum+i;} i++; } document.write("<br>There are " +count); document.write(" even numbers between "+a); document.write(" and "+n); document.write("<br> and sum of these " +count); document.write(" even numbers is "+sum); </script> </font></body> </html>

32 | P a g e

33 | P a g e

34 | P a g e

PROGRAM 12 AIM: To find out the numbers divisible by 3 & 5 between the two numbers by using For Loop <html> <head> <title>Javascript</title> </head> <body> <font size="15"> <script language="javascript"> var a,i,n,count=0; i=parseInt(prompt("Please enter the ist number")); n=parseInt(prompt("Please enter the last number")); a=i; document.write("Between "+i); document.write(" and "+n); document.write(", Following numbers are divisible by 3 & 5:<br>"); for(i=1;i<=n;i++) if(i%3==0 && i%5==0) {document.write(i+","); count++;} document.write("<br>There are " +count); document.write(" numbers between "+a); document.write(" and "+n); document.write(", which are divisible by 3 & 5"); </script> </font> </body> </html>

35 | P a g e

36 | P a g e

37 | P a g e

PROGRAM 13 AIM: To find the greatest of three numbers using function <html> <head> <title>Javascript Function</title> <script language="javascript"> function big(a,b,c) { if(a>=b) g=a; else g=b; if(g>=c) alert("The greatest number is " +g); else alert("The greatest number is " +c); } </script> </head> <body> <script language="javascript"> var a,b,c,g; a=parseInt(prompt("Enter the first number","")); b=parseInt(prompt("Enter the 2nd number","")); c=parseInt(prompt("Enter the 3rd number","")); big(a,b,c); </script></body> </html>

38 | P a g e

39 | P a g e

40 | P a g e

PROGRAM 14 AIM: To find the percentage of marks obtained using function with return <html> <head> <title>Javascript Function</title> <script language="javascript"> function per(a,b,c) {var total,p; total=a+b+c; p=total/3; return(p) } </script> </head> <body> <font size="15"> <script language="javascript"> var a,b,c,result; a=parseInt(prompt("Please enter the marks of ASM ")); b=parseInt(prompt("Please enter the marks of FSM ")); c=parseInt(prompt("Please enter the marks of MR ")); result=per(a,b,c); document.write("You have obtained "+result); document.write("% marks "); </script> </font> </body> </html>

41 | P a g e

42 | P a g e

43 | P a g e