SlideShare a Scribd company logo
AAFREEN SHAIKH pg. 1
CHHATRAPATI SHIVAJI JUNIOR SCIENCE COLLEGE JALGAON
JAVASCRIPT PROGRAMS
1.Write JavaScript code to print subtraction of 2 numbers.
<html>
<head>
<title>JS program to subtract two numbers</title>
</head>
<body>
<script>
var n1, n2, diff;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
diff=n2-n1;
alert("Subtraction - " + diff);
</script>
</body>
</html>
2.Write JavaScript code to print addition of 2 numbers.
<html>
<head>
<title>JS program to add two numbers</title>
</head>
<body>
<script>
var n1, n2, sum;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
sum=n1+n2;
alert("Sum- " + sum);
</script>
</body>
</html>
3.Write JavaScript code to print multiplication of 2 numbers.
<html>
<head>
<title>JS program to multiply two numbers</title>
</head>
<body>
<script>
AAFREEN SHAIKH pg. 2
var n1, n2, prod;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
prod=n1*n2;
alert("Product - " + prod);
</script>
</body>
</html>
4.Write JavaScript code to print division of 2 numbers.
<html>
<head>
<title>JS program to divide two numbers</title>
</head>
<body>
<script>
var n1, n2, q;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
q=n1/n2;
alert("Division - " + q);
</script>
</body>
</html>
5.Write JavaScript code to print addition, subtraction, multiplication & division of 2
numbers.
<html>
<head>
<title>JS program to add, subtract, multiply, divide two numbers</title>
</head>
<body>
<script>
var n1, n2, s,d,m,q;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
s=n1+n2;
d=n2-n1;
m=n1*n2;
q=n1/n2;
document.write("<br>Sum - " + s);
document.write("<br>Difference - " + d);
document.write("<br>Product - " + m);
document.write("<br>Division - " + q);
</script>
</body>
AAFREEN SHAIKH pg. 3
</html>
6.Write JavaScript code to display area of circle, accept value from user.
7.Write JavaScript code to print area of triangle.
<html>
<head>
<title>JS program to calculate area of circle</title>
</head>
<body>
<script>
var r, area;
r=parseInt(prompt("Enter radius of the circle:"));
area=3.14*r*r;
alert("Area - " + area);
</script>
</body>
</html>
8.Write JavaScript code to calculate the average of three numbers.
<html>
<head>
<title>JS program to calculate average of three numbers</title>
</head>
<body>
<script>
var n1, n2, n3 avg;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
n3=parseInt(prompt("Enter third number:"));
avg=(n1+n2+n3)/3;
alert("Average - " + avg);
</script>
</body>
</html>
9.Write JavaScript code to print perimeter of rectangle.
<html>
<head>
<title>JS program to calculate perimeter of rectangle</title>
</head>
<body>
<script>
AAFREEN SHAIKH pg. 4
var length, breadth, p;
length=parseInt(prompt("Enter length of the rectangle:"));
breadth=parseInt(prompt("Enter breadth of the rectangle:"));
p=2*(length+breadth);
alert("Perimeter- " + p);
</script>
</body>
</html>
10.Write JavaScript code to print perimeter of trapezium.
<html>
<head>
<title>JS program to calculate perimeter of trapezium</title>
</head>
<body>
<script>
var a, b, c, d, p;
a=parseInt(prompt("Enter length of the first side of trapezium:"));
b=parseInt(prompt("Enter length of the second side of trapezium:"));
c=parseInt(prompt("Enter length of the third side of trapezium:"));
d=parseInt(prompt("Enter length of the fourth side of trapezium:"));
p=a+b+c+d;
alert("Perimeter - " + p);
</script>
</body>
</html>
11.Write JavaScript code to check whether the number is odd or even.
<html>
<head>
<title>JS program to check number is odd or even</title>
</head>
<body>
<script>
var n;
n=parseInt(prompt("Enter a number:"));
if(n%2==0)
alert("Number is even");
else
alert("Number is odd");
</script>
</body>
</html>
AAFREEN SHAIKH pg. 5
12. Write JavaScript code to enter two values and display the largest.
<html>
<head>
<title>JS program to find largest number</title>
</head>
<body>
<script>
var n1, n2;
n1=parseInt(prompt("Enter first number:"));
n2=parseInt(prompt("Enter second number:"));
if(n1>n2)
alert("Larger number - " + n1);
else
alert("Larger number - " + n2);
</script>
</body>
</html>
13. Write JavaScript code to print multiplication table of 3.
<html>
<head>
<title>JS program to print multiplication table of 3</title>
</head>
<body>
<script>
var n=3, i;
document.write("Multiplication table of 3");
for(i=1;i<=10;i++)
{
document.write("<br>"+n+" * "+i+" = "+n*i);
}
</script>
</body>
</html>
14.Write JavaScript code to print numbers from 1 to 10.
<html>
<head>
<title>JS program to print numbers from 1 to 10</title>
</head>
<body>
AAFREEN SHAIKH pg. 6
<script>
var i;
document.write("Numbers from 1 to 10");
for(i=1;i<=10;i++)
{
document.write("<br>"+i);
}
</script>
</body>
</html>
15.Write JavaScript code to print sum of 50 natural numbers.
<html>
<head>
<title>JS program to print sum of 50 natural numbers.</title>
</head>
<body>
<script>
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("<br>Sum - "+sum);
</script>
</body>
</html>
16.Write JavaScript code to print all even numbers from 10 to 50.
<html>
<head>
<title>JS program to print even numbers from 10 to 50</title>
</head>
<body>
<script>
var i;
document.write("Even Numbers from 10 to 50");
for(i=10;i<=50;i++)
{
if(i%2==0)
document.write("<br>"+i);
}
AAFREEN SHAIKH pg. 7
</script>
</body>
</html>
17.Write JavaScript code when user click on button, it will display sum of even numbers
from 1 to 10.
<html>
<head>
<title>JS program to print sum of even numbers.</title>
<script>
function display_sum() {
var i, sum=0;
for(i=1;i<=10;i++)
{
if(i%2==0)
sum=sum+i;
}
document.getElementById("disp").innerHTML= "Sum of even numbers from 1to10 - " +
sum;
}
</script>
</head>
<body>
<input type="button" name="disp_sum" value="Display Sum" onclick="display_sum()">
<br>
<p id="disp"> </p>
</body>
</html>
18.Write JavaScript code to print all odd numbers from 50 to 100.
<html>
<head>
<title>JS program </title>
</head>
<body>
<h1>JS program to print odd numbers from 50 to 100</h1>
<script>
var i;
document.write("Odd Numbers from 50 to 100");
for(i=50;i<=100;i++)
{
AAFREEN SHAIKH pg. 8
if(i%2!=0)
document.write("<br>"+i);
}
</script>
</body>
</html>
19.Write JavaScript code to print factorial of 7 on button click.
<html>
<head>
<title>JS program - factorial of number</title>
<script>
function display_factorial(num) {
var i, f = 1;
for (i = num; i >= 1; i--) {
f=f*i;
}
document.getElementById("disp").innerHTML = "Factorial of 7 - " + f;
}
</script>
</head>
<body>
<h1>JS program to print factorial of number</h1>
<input type="button" name="disp_fact" value="Display Factorial"
onclick="display_factorial(7)">
<br>
<p id="disp"> </p>
</body>
</html>
20.Write JavaScript code to print square of a accepted number.
<html>
<head>
<title>JS program to display square of a number</title>
</head>
<body>
<script>
var n, r;
n=parseInt(prompt("Enter a number:"));
r=n*n
alert("Square - " + r);
AAFREEN SHAIKH pg. 9
</script>
</body>
</html>
21.Write JavaScript code to count length of accepted string after click on the button.
<html>
<head>
<title>JS program</title>
<script>
function display_length() {
var str, len;
str = form1.str_box.value;
len = str.length;
document.getElementById("disp").innerHTML = "Length of String - " + len;
}
</script>
</head>
<body>
<h1>JS program to print length of string</h1>
<form name="form1">
<input type="text" name="str_box" size=50>
<input type="button" name="disp_strlen" value="Display Length"
onclick="display_length()">
</form>
<br>
<p id="disp"> </p>
</body>
</html>
22.Write JavaScript code to accept two dates and find the difference in those dates.
<html>
<head>
<title>JS program</title>
<script>
function display_diff() {
var d1, d2, diff;
d1 = new Date(form1.date1.value);
d2 = new Date(form1.date2.value);
diff = (d2 - d1) / (1000 * 3600 * 24);
document.getElementById("disp").innerHTML = "Difference of dates in days - " + diff;
}
</script>
</head>
<body>
<h1>JS program to display difference between dates</h1>
<form name="form1">
AAFREEN SHAIKH pg. 10
<input type="date" name="date1">
<br> <br>
<input type="date" name="date2">
<br> <br>
<input type="button" name="disp_diff" value="Display Difference"
onclick="display_diff()">
</form>
<br>
<p id="disp"> </p>
</body>
</html>
23.Write JavaScript code to take a input of string and reverse the string in output.
<html>
<head>
<title>JS program - revverse of string</title>
<script>
function display_reverse(str) {
var newstr;
newstr = str.split("").reverse().join("")
document.write("Reverse of String - " + newstr);
}
</script>
</head>
<body>
<h1>JS program to reverse a string</h1>
<script>
var s;
s = prompt("Input a string");
display_reverse(s)
</script>
</body>
</html>

More Related Content

Similar to JAVASCRIPT PROGRAM.pdf

labb123456789123456789123456789123456789
labb123456789123456789123456789123456789labb123456789123456789123456789123456789
labb123456789123456789123456789123456789
Ghh
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
Zaibi Gondal
 
Web lab programs
Web lab programsWeb lab programs
Web lab programs
SRINIVASUNIVERSITYEN
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
Thesis Scientist Private Limited
 
Javascript
JavascriptJavascript
Javascript
Rajavel Dhandabani
 
Javascript notes
Javascript notesJavascript notes
Javascript notes
Parveen Jaat
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
MuhammadMaazShaik
 
C
CC
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
Prof. Dr. K. Adisesha
 
Hargun
HargunHargun
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Salar Delavar Qashqai
 
Pnno
PnnoPnno
Introduction to java script Lecture 4.ppt
Introduction to java script Lecture 4.pptIntroduction to java script Lecture 4.ppt
Introduction to java script Lecture 4.ppt
dejen6
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 

Similar to JAVASCRIPT PROGRAM.pdf (20)

labb123456789123456789123456789123456789
labb123456789123456789123456789123456789labb123456789123456789123456789123456789
labb123456789123456789123456789123456789
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Web lab programs
Web lab programsWeb lab programs
Web lab programs
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Javascript
JavascriptJavascript
Javascript
 
Javascript notes
Javascript notesJavascript notes
Javascript notes
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
C
CC
C
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Hargun
HargunHargun
Hargun
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...Geometric and material nonlinearity analysis of 2 d truss with force and duct...
Geometric and material nonlinearity analysis of 2 d truss with force and duct...
 
Pnno
PnnoPnno
Pnno
 
Introduction to java script Lecture 4.ppt
Introduction to java script Lecture 4.pptIntroduction to java script Lecture 4.ppt
Introduction to java script Lecture 4.ppt
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
C important questions
C important questionsC important questions
C important questions
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 

More from AAFREEN SHAIKH

Hsc computer science Networking technology (1).pdf
Hsc computer science Networking technology (1).pdfHsc computer science Networking technology (1).pdf
Hsc computer science Networking technology (1).pdf
AAFREEN SHAIKH
 
Hsc computer science chap 4.HTML2024.pdf
Hsc computer science chap 4.HTML2024.pdfHsc computer science chap 4.HTML2024.pdf
Hsc computer science chap 4.HTML2024.pdf
AAFREEN SHAIKH
 
Hsc computer science paper 1 chap 1 OperatingSystem2024.pdf
Hsc computer science paper 1 chap 1 OperatingSystem2024.pdfHsc computer science paper 1 chap 1 OperatingSystem2024.pdf
Hsc computer science paper 1 chap 1 OperatingSystem2024.pdf
AAFREEN SHAIKH
 
Hsc computer science chap 1 Operating System (1).pdf
Hsc computer science chap 1 Operating System  (1).pdfHsc computer science chap 1 Operating System  (1).pdf
Hsc computer science chap 1 Operating System (1).pdf
AAFREEN SHAIKH
 
Hsc IT 6. E-Commerce and E-Governance_.pdf
Hsc IT 6. E-Commerce and E-Governance_.pdfHsc IT 6. E-Commerce and E-Governance_.pdf
Hsc IT 6. E-Commerce and E-Governance_.pdf
AAFREEN SHAIKH
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
Hac IT 4. Emerging Technologies (1).pdf
Hac IT 4. Emerging Technologies  (1).pdfHac IT 4. Emerging Technologies  (1).pdf
Hac IT 4. Emerging Technologies (1).pdf
AAFREEN SHAIKH
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
AAFREEN SHAIKH
 
2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf
2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf
2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf
AAFREEN SHAIKH
 
1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf
AAFREEN SHAIKH
 
Maharashtra state board exam IT Chap 6.pdf
Maharashtra state board exam IT Chap 6.pdfMaharashtra state board exam IT Chap 6.pdf
Maharashtra state board exam IT Chap 6.pdf
AAFREEN SHAIKH
 
Maharashtra state board IT science Chap 5.pdf
Maharashtra state board IT science Chap 5.pdfMaharashtra state board IT science Chap 5.pdf
Maharashtra state board IT science Chap 5.pdf
AAFREEN SHAIKH
 
Maharashtra state board IT science Chap 4.pdf
Maharashtra state board IT science Chap 4.pdfMaharashtra state board IT science Chap 4.pdf
Maharashtra state board IT science Chap 4.pdf
AAFREEN SHAIKH
 
Maharashtra state board Hsc IT Chap 3.pdf
Maharashtra state board Hsc IT Chap 3.pdfMaharashtra state board Hsc IT Chap 3.pdf
Maharashtra state board Hsc IT Chap 3.pdf
AAFREEN SHAIKH
 
Maharashtra state board Hsc IT Chap 1 advance web designing.pdf
Maharashtra state board Hsc IT Chap 1 advance web designing.pdfMaharashtra state board Hsc IT Chap 1 advance web designing.pdf
Maharashtra state board Hsc IT Chap 1 advance web designing.pdf
AAFREEN SHAIKH
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdfHSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdf
AAFREEN SHAIKH
 
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdfHSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdf
AAFREEN SHAIKH
 
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdfHSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdf
AAFREEN SHAIKH
 

More from AAFREEN SHAIKH (19)

Hsc computer science Networking technology (1).pdf
Hsc computer science Networking technology (1).pdfHsc computer science Networking technology (1).pdf
Hsc computer science Networking technology (1).pdf
 
Hsc computer science chap 4.HTML2024.pdf
Hsc computer science chap 4.HTML2024.pdfHsc computer science chap 4.HTML2024.pdf
Hsc computer science chap 4.HTML2024.pdf
 
Hsc computer science paper 1 chap 1 OperatingSystem2024.pdf
Hsc computer science paper 1 chap 1 OperatingSystem2024.pdfHsc computer science paper 1 chap 1 OperatingSystem2024.pdf
Hsc computer science paper 1 chap 1 OperatingSystem2024.pdf
 
Hsc computer science chap 1 Operating System (1).pdf
Hsc computer science chap 1 Operating System  (1).pdfHsc computer science chap 1 Operating System  (1).pdf
Hsc computer science chap 1 Operating System (1).pdf
 
Hsc IT 6. E-Commerce and E-Governance_.pdf
Hsc IT 6. E-Commerce and E-Governance_.pdfHsc IT 6. E-Commerce and E-Governance_.pdf
Hsc IT 6. E-Commerce and E-Governance_.pdf
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
Hac IT 4. Emerging Technologies (1).pdf
Hac IT 4. Emerging Technologies  (1).pdfHac IT 4. Emerging Technologies  (1).pdf
Hac IT 4. Emerging Technologies (1).pdf
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
 
2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf
2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf
2. Introduction to SEO 2 (Search Engine Optimization) (12th IT).pdf
 
1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf1. Advanced Web Designing (12th IT) (1).pdf
1. Advanced Web Designing (12th IT) (1).pdf
 
Maharashtra state board exam IT Chap 6.pdf
Maharashtra state board exam IT Chap 6.pdfMaharashtra state board exam IT Chap 6.pdf
Maharashtra state board exam IT Chap 6.pdf
 
Maharashtra state board IT science Chap 5.pdf
Maharashtra state board IT science Chap 5.pdfMaharashtra state board IT science Chap 5.pdf
Maharashtra state board IT science Chap 5.pdf
 
Maharashtra state board IT science Chap 4.pdf
Maharashtra state board IT science Chap 4.pdfMaharashtra state board IT science Chap 4.pdf
Maharashtra state board IT science Chap 4.pdf
 
Maharashtra state board Hsc IT Chap 3.pdf
Maharashtra state board Hsc IT Chap 3.pdfMaharashtra state board Hsc IT Chap 3.pdf
Maharashtra state board Hsc IT Chap 3.pdf
 
Maharashtra state board Hsc IT Chap 1 advance web designing.pdf
Maharashtra state board Hsc IT Chap 1 advance web designing.pdfMaharashtra state board Hsc IT Chap 1 advance web designing.pdf
Maharashtra state board Hsc IT Chap 1 advance web designing.pdf
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdfHSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART II.pdf
 
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdfHSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART I.pdf
 
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdfHSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdf
HSC INFORMATION TECHNOLOGY CHAPTER 1 ADVANCED WEB DESIGNING PART III.pdf
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 

JAVASCRIPT PROGRAM.pdf

  • 1. AAFREEN SHAIKH pg. 1 CHHATRAPATI SHIVAJI JUNIOR SCIENCE COLLEGE JALGAON JAVASCRIPT PROGRAMS 1.Write JavaScript code to print subtraction of 2 numbers. <html> <head> <title>JS program to subtract two numbers</title> </head> <body> <script> var n1, n2, diff; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); diff=n2-n1; alert("Subtraction - " + diff); </script> </body> </html> 2.Write JavaScript code to print addition of 2 numbers. <html> <head> <title>JS program to add two numbers</title> </head> <body> <script> var n1, n2, sum; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); sum=n1+n2; alert("Sum- " + sum); </script> </body> </html> 3.Write JavaScript code to print multiplication of 2 numbers. <html> <head> <title>JS program to multiply two numbers</title> </head> <body> <script>
  • 2. AAFREEN SHAIKH pg. 2 var n1, n2, prod; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); prod=n1*n2; alert("Product - " + prod); </script> </body> </html> 4.Write JavaScript code to print division of 2 numbers. <html> <head> <title>JS program to divide two numbers</title> </head> <body> <script> var n1, n2, q; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); q=n1/n2; alert("Division - " + q); </script> </body> </html> 5.Write JavaScript code to print addition, subtraction, multiplication & division of 2 numbers. <html> <head> <title>JS program to add, subtract, multiply, divide two numbers</title> </head> <body> <script> var n1, n2, s,d,m,q; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); s=n1+n2; d=n2-n1; m=n1*n2; q=n1/n2; document.write("<br>Sum - " + s); document.write("<br>Difference - " + d); document.write("<br>Product - " + m); document.write("<br>Division - " + q); </script> </body>
  • 3. AAFREEN SHAIKH pg. 3 </html> 6.Write JavaScript code to display area of circle, accept value from user. 7.Write JavaScript code to print area of triangle. <html> <head> <title>JS program to calculate area of circle</title> </head> <body> <script> var r, area; r=parseInt(prompt("Enter radius of the circle:")); area=3.14*r*r; alert("Area - " + area); </script> </body> </html> 8.Write JavaScript code to calculate the average of three numbers. <html> <head> <title>JS program to calculate average of three numbers</title> </head> <body> <script> var n1, n2, n3 avg; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); n3=parseInt(prompt("Enter third number:")); avg=(n1+n2+n3)/3; alert("Average - " + avg); </script> </body> </html> 9.Write JavaScript code to print perimeter of rectangle. <html> <head> <title>JS program to calculate perimeter of rectangle</title> </head> <body> <script>
  • 4. AAFREEN SHAIKH pg. 4 var length, breadth, p; length=parseInt(prompt("Enter length of the rectangle:")); breadth=parseInt(prompt("Enter breadth of the rectangle:")); p=2*(length+breadth); alert("Perimeter- " + p); </script> </body> </html> 10.Write JavaScript code to print perimeter of trapezium. <html> <head> <title>JS program to calculate perimeter of trapezium</title> </head> <body> <script> var a, b, c, d, p; a=parseInt(prompt("Enter length of the first side of trapezium:")); b=parseInt(prompt("Enter length of the second side of trapezium:")); c=parseInt(prompt("Enter length of the third side of trapezium:")); d=parseInt(prompt("Enter length of the fourth side of trapezium:")); p=a+b+c+d; alert("Perimeter - " + p); </script> </body> </html> 11.Write JavaScript code to check whether the number is odd or even. <html> <head> <title>JS program to check number is odd or even</title> </head> <body> <script> var n; n=parseInt(prompt("Enter a number:")); if(n%2==0) alert("Number is even"); else alert("Number is odd"); </script> </body> </html>
  • 5. AAFREEN SHAIKH pg. 5 12. Write JavaScript code to enter two values and display the largest. <html> <head> <title>JS program to find largest number</title> </head> <body> <script> var n1, n2; n1=parseInt(prompt("Enter first number:")); n2=parseInt(prompt("Enter second number:")); if(n1>n2) alert("Larger number - " + n1); else alert("Larger number - " + n2); </script> </body> </html> 13. Write JavaScript code to print multiplication table of 3. <html> <head> <title>JS program to print multiplication table of 3</title> </head> <body> <script> var n=3, i; document.write("Multiplication table of 3"); for(i=1;i<=10;i++) { document.write("<br>"+n+" * "+i+" = "+n*i); } </script> </body> </html> 14.Write JavaScript code to print numbers from 1 to 10. <html> <head> <title>JS program to print numbers from 1 to 10</title> </head> <body>
  • 6. AAFREEN SHAIKH pg. 6 <script> var i; document.write("Numbers from 1 to 10"); for(i=1;i<=10;i++) { document.write("<br>"+i); } </script> </body> </html> 15.Write JavaScript code to print sum of 50 natural numbers. <html> <head> <title>JS program to print sum of 50 natural numbers.</title> </head> <body> <script> 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("<br>Sum - "+sum); </script> </body> </html> 16.Write JavaScript code to print all even numbers from 10 to 50. <html> <head> <title>JS program to print even numbers from 10 to 50</title> </head> <body> <script> var i; document.write("Even Numbers from 10 to 50"); for(i=10;i<=50;i++) { if(i%2==0) document.write("<br>"+i); }
  • 7. AAFREEN SHAIKH pg. 7 </script> </body> </html> 17.Write JavaScript code when user click on button, it will display sum of even numbers from 1 to 10. <html> <head> <title>JS program to print sum of even numbers.</title> <script> function display_sum() { var i, sum=0; for(i=1;i<=10;i++) { if(i%2==0) sum=sum+i; } document.getElementById("disp").innerHTML= "Sum of even numbers from 1to10 - " + sum; } </script> </head> <body> <input type="button" name="disp_sum" value="Display Sum" onclick="display_sum()"> <br> <p id="disp"> </p> </body> </html> 18.Write JavaScript code to print all odd numbers from 50 to 100. <html> <head> <title>JS program </title> </head> <body> <h1>JS program to print odd numbers from 50 to 100</h1> <script> var i; document.write("Odd Numbers from 50 to 100"); for(i=50;i<=100;i++) {
  • 8. AAFREEN SHAIKH pg. 8 if(i%2!=0) document.write("<br>"+i); } </script> </body> </html> 19.Write JavaScript code to print factorial of 7 on button click. <html> <head> <title>JS program - factorial of number</title> <script> function display_factorial(num) { var i, f = 1; for (i = num; i >= 1; i--) { f=f*i; } document.getElementById("disp").innerHTML = "Factorial of 7 - " + f; } </script> </head> <body> <h1>JS program to print factorial of number</h1> <input type="button" name="disp_fact" value="Display Factorial" onclick="display_factorial(7)"> <br> <p id="disp"> </p> </body> </html> 20.Write JavaScript code to print square of a accepted number. <html> <head> <title>JS program to display square of a number</title> </head> <body> <script> var n, r; n=parseInt(prompt("Enter a number:")); r=n*n alert("Square - " + r);
  • 9. AAFREEN SHAIKH pg. 9 </script> </body> </html> 21.Write JavaScript code to count length of accepted string after click on the button. <html> <head> <title>JS program</title> <script> function display_length() { var str, len; str = form1.str_box.value; len = str.length; document.getElementById("disp").innerHTML = "Length of String - " + len; } </script> </head> <body> <h1>JS program to print length of string</h1> <form name="form1"> <input type="text" name="str_box" size=50> <input type="button" name="disp_strlen" value="Display Length" onclick="display_length()"> </form> <br> <p id="disp"> </p> </body> </html> 22.Write JavaScript code to accept two dates and find the difference in those dates. <html> <head> <title>JS program</title> <script> function display_diff() { var d1, d2, diff; d1 = new Date(form1.date1.value); d2 = new Date(form1.date2.value); diff = (d2 - d1) / (1000 * 3600 * 24); document.getElementById("disp").innerHTML = "Difference of dates in days - " + diff; } </script> </head> <body> <h1>JS program to display difference between dates</h1> <form name="form1">
  • 10. AAFREEN SHAIKH pg. 10 <input type="date" name="date1"> <br> <br> <input type="date" name="date2"> <br> <br> <input type="button" name="disp_diff" value="Display Difference" onclick="display_diff()"> </form> <br> <p id="disp"> </p> </body> </html> 23.Write JavaScript code to take a input of string and reverse the string in output. <html> <head> <title>JS program - revverse of string</title> <script> function display_reverse(str) { var newstr; newstr = str.split("").reverse().join("") document.write("Reverse of String - " + newstr); } </script> </head> <body> <h1>JS program to reverse a string</h1> <script> var s; s = prompt("Input a string"); display_reverse(s) </script> </body> </html>