Java script Assignment
June 3, 2026 6 min read

Java script assignments

HS
HEMANT SINGH
Technical Writer & Educator

JavaScript Assignments

1. Basic JavaScript Programs

  1. Create an external JavaScript file and import it into an HTML file.
  2. Write an internal JavaScript program (placed before the closing </body> tag) to display the user's name.
  3. Display your college name using the <h1> tag.
  4. Display your permanent address using the <font> tag.
  5. Display your favorite car name using the <marquee> tag.
  6. Display your biodata using an external JavaScript file.
  7. Display your favorite city name using template literals (backticks `` `).
  8. Display your name, father's name, date of birth, and mobile number using a single document.write() statement with template literals.

2. Variable Declaration & Initialization

Write JavaScript programs to calculate the following:

Circle

  1. Area = π × r²
  2. Perimeter = 2 × π × r

Square

  1. Area = side × side
  2. Perimeter = 4 × side

Rectangle

  1. Area = length × width
  2. Perimeter = 2 × (length + width)

Right-Angled Triangle

  1. Area = (base × height) / 2
  2. Perimeter = side1 + side2 + side3

Volume Calculations

Cube

  1. Volume = a³

Cylinder

  1. Volume = 3.14 × r² × h

Cone

  1. Volume = (3.14 × r² × h) / 3

Sphere

  1. Volume = (4/3) × 3.14 × r³

3. Conditional Programs

  1. Swap two numbers using a third variable.
  2. Swap two numbers without using a third variable.
  3. Count the number of ₹2000, ₹500, and ₹200 notes in a given amount.
  4. Calculate Simple Interest.
  5. Check whether a number is even or odd.
  6. Check whether a person is eligible to vote.
  7. Check whether two numbers are equal.
  8. Find the largest of two numbers.
  9. Check whether a year is a leap year.
  10. Check whether a number is divisible by 5.
  11. Check whether a number is divisible by 5 or 7.
  12. Check whether a number is divisible by both 11 and 17.
  13. Check whether two variables are not equal.
  14. Display the day name corresponding to numbers (1–7).
  15. Display the month name corresponding to numbers (1–12).
  16. Check whether a student has passed based on marks in three subjects (passing marks must be greater than 33).
  17. Find the student's grade based on percentage:

Grade

Percentage

A

Greater than 90%

B

Greater than 80%

C

Greater than 70%

D

Greater than or equal to 60%

E

Less than 60%

  1. Create a calculator using a switch statement to perform:
  2. Addition
  3. Subtraction
  4. Multiplication
  5. Division
  6. Check whether a number is even or odd using the conditional (ternary) operator.
  7. Find the largest among three different numbers.

4. Logical Operator Programs

Scholarship Eligibility

A student gets a scholarship if:

  1. Marks ≥ 85 AND
  2. Attendance ≥ 75%

Otherwise, display "Not Eligible".

Discount Offer

A customer gets a discount if:

  1. Bill Amount ≥ ₹2000 OR
  2. Customer is a premium member.

Otherwise, no discount.

Exam Pass/Fail

A student passes if:

  1. Marks ≥ 40 AND
  2. Not absent.

If absent, display "Fail due to Absence".

Login Validation

  1. Username = "admin" AND Password = "1234" → Login Success
  2. Username = "admin" AND Password ≠ "1234" → Wrong Password
  3. Username ≠ "admin" → Wrong Username

Job Application

Eligible if:

  1. Qualification = Graduate
  2. AND (Experience ≥ 2 years OR Age < 25)

Festival Offer

A customer gets a special gift if:

  1. Shopping Amount ≥ ₹5000
  2. OR (Premium Member AND Shopping Amount ≥ ₹3000)

Temperature Category

Take the temperature as input and display the appropriate category:

  1. Above 40 → Very Hot
  2. 30–40 → Hot
  3. 20–29 → Normal
  4. 10–19 → Cold
  5. Below 10 → Very Cold

Take the number of electricity units consumed as input and display the consumption category:

  1. 0–100 → Low Consumption
  2. 101–300 → Medium Consumption
  3. 301–500 → High Consumption
  4. Above 500 → Very High Consumption

Salary Category

Take a person's salary as input and display the appropriate category:

  1. Below ₹20,000 → Low Salary
  2. ₹20,000–₹50,000 → Average Salary
  3. ₹50,001–₹1,00,000 → Good Salary
  4. Above ₹1,00,000 → High Salary

Student Result System

Take marks for five subjects as input.

Perform the following tasks:

  1. Calculate the total marks.
  2. Calculate the percentage.
  3. If the student scores below 33 in any subject, display Fail.
  4. Otherwise, assign a grade based on the percentage.

Use both nested if and if-else-if statements.

Online Shopping Discount System

Create an online shopping discount system.

Take the following inputs:

  1. Product price
  2. Membership status
  3. Coupon code

Apply the following conditions:

  1. Apply a discount if the product price is above ₹5,000.
  2. Apply an additional discount for members.
  3. Apply another discount if the coupon code is valid.
  4. Calculate and display the final payable amount.

Create a program to check whether a customer is eligible for a bank loan.

Take the following inputs:

  1. Age
  2. Monthly salary
  3. Credit score

The customer is eligible only if:

  1. Age is 21 or above.
  2. Monthly salary is ₹25,000 or above.
  3. Credit score is 700 or above.

If the loan is rejected, display the appropriate reason.

Restaurant Billing System

Create a restaurant billing program with the following menu:

  1. Pizza – ₹250
  2. Burger – ₹150
  3. Pasta – ₹200
  4. Coffee – ₹100

Use a switch statement to select the food item.

Take the quantity as input and calculate the total bill.

If the total bill exceeds ₹1,000, apply a 10% discount.

Finally, display the total bill, discount amount, and final payable amount.

5. For Loop Programs

  1. Display numbers from:
  2. 1 to 100
  3. 100 to 1
  4. -10 to 10
  5. 10 to -10
  6. -10 to -20
  7. Display even numbers from 1–100.
  8. Display odd numbers from 32–64.
  9. Count, calculate the sum, and multiplication of numbers from 1–7.
  10. Check whether a number is prime.
  11. Find the factorial of a number.
  12. Display the multiplication table of a given number.

6. While Loop Programs

  1. Display numbers for:
  2. 1 to 100
  3. 100 to 1
  4. -10 to 10
  5. 10 to -10
  6. -10 to -20
  7. Display even numbers from 1–100.
  8. Display odd numbers from 32–64.
  9. Count, calculate the sum, and multiplication of numbers from 1–7.
  10. Check whether a number is prime.
  11. Find the factorial of a number.
  12. Display the multiplication table of a given number.
  13. Display digits of a given number.
  14. Count, calculate the sum, and multiplication of digits.
  15. Check whether a number is a palindrome.
  16. Check whether a number is an Armstrong number.
  17. Check whether a number is a Special number.

7. Do-While Loop Programs

  1. Display numbers for:
  2. 1 to 100
  3. 100 to 1
  4. -10 to 10
  5. 10 to -10
  6. -10 to -20
  7. Display even numbers from 1–100.
  8. Display odd numbers from 32–64.
  9. Count, calculate the sum, and multiplication from 1–7.
  10. Check whether a number is prime.
  11. Find the factorial of a number.
  12. Display the multiplication table of a given number.

8. Nested Loop Programs

  1. Display all prime numbers from 1–100.
  2. Display multiplication tables from 1–10.

Pattern Programs

Pattern 1

111
222
333

Pattern 2

123
123
123

Pattern 3

666
666
666

Pattern 4

123
456
789

Pattern 5

987
654
321

Pattern 6

****
****
****
****

Pattern 7

*
**
***
****

Pattern 8

****
***
**
*

Pattern 9

*
**
***
****

Pattern 10

****
***
**
*

Pattern 11

*
***
*****
*******

Pattern 12

*******
*****
***
*

9. Array Programs

  1. Store and print the following numbers:
45, 7, 0, 90, -90, 89, 34, -45, 60
  1. Calculate the count and sum of the array.
  2. Print only even numbers.
  3. Print numbers divisible by 5.
  4. Print numbers divisible by both 5 and 11.
  5. Print Special numbers.
  6. Print Palindrome numbers.
  7. Print Armstrong numbers.
  8. Find the position and index of 8.
  9. Find the frequency (mode) of 10.
  10. Find the average of the array.

10. Two-Dimensional Array Programs

  1. Store and display:
1 0 0
0 1 0
0 0 1
  1. Store and display:
10 20 30 40
50 60 70 80
  1. Display:
  2. First row
  3. Second row
  4. Third row
  5. First column
  6. Second column
  7. Third column
  8. Left diagonal
  9. Right diagonal
  10. Add two matrices.
  11. Subtract two matrices.
  12. Find the transpose of a matrix.

11. Functions

  1. Create a function to display the user's name.
  2. Create a function to check whether a number is even or odd.
  3. Create a parameterized function to add a leading 0 to a single-digit number.
  4. Create a non-parameterized function to calculate the sum of two numbers.
  5. Create a function to display numbers from 1–10 using a while loop.
  6. Create a function that returns the greater number.
  7. Create a function that returns all even numbers from the array:
{1, 45, 5, 6, 68, 90, 102, 0, 90}

12. Event Handling

  1. Create a button and display an alert on click.
  2. Create an <h1> element and display a console message on click.
  3. Create a button and paragraph with a common click function that displays an alert.
  4. Create an <h1> element and button to get the value of the heading.
  5. Create an <h1> element and button to change the heading text.

13. Form Handling

  1. Create a form with a Name input and retrieve its value.
  2. Create a form with a Password input and retrieve its value.
  3. Create a form with a Date input and retrieve its value.
  4. Create a form with a Textarea and retrieve its value.
  5. Create a form with a School dropdown and retrieve its selected value.
  6. Create a form with an Age (Number) input and retrieve its value.