JavaScript Assignments
1. Basic JavaScript Programs
- Create an external JavaScript file and import it into an HTML file.
- Write an internal JavaScript program (placed before the closing
</body>tag) to display the user's name. - Display your college name using the
<h1>tag. - Display your permanent address using the
<font>tag. - Display your favorite car name using the
<marquee>tag. - Display your biodata using an external JavaScript file.
- Display your favorite city name using template literals (backticks `` `).
- 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
- Area = π × r²
- Perimeter = 2 × π × r
Square
- Area = side × side
- Perimeter = 4 × side
Rectangle
- Area = length × width
- Perimeter = 2 × (length + width)
Right-Angled Triangle
- Area = (base × height) / 2
- Perimeter = side1 + side2 + side3
Volume Calculations
Cube
- Volume = a³
Cylinder
- Volume = 3.14 × r² × h
Cone
- Volume = (3.14 × r² × h) / 3
Sphere
- Volume = (4/3) × 3.14 × r³
3. Conditional Programs
- Swap two numbers using a third variable.
- Swap two numbers without using a third variable.
- Count the number of ₹2000, ₹500, and ₹200 notes in a given amount.
- Calculate Simple Interest.
- Check whether a number is even or odd.
- Check whether a person is eligible to vote.
- Check whether two numbers are equal.
- Find the largest of two numbers.
- Check whether a year is a leap year.
- Check whether a number is divisible by 5.
- Check whether a number is divisible by 5 or 7.
- Check whether a number is divisible by both 11 and 17.
- Check whether two variables are not equal.
- Display the day name corresponding to numbers (1–7).
- Display the month name corresponding to numbers (1–12).
- Check whether a student has passed based on marks in three subjects (passing marks must be greater than 33).
- 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% |
- Create a calculator using a
switchstatement to perform: - Addition
- Subtraction
- Multiplication
- Division
- Check whether a number is even or odd using the conditional (ternary) operator.
- Find the largest among three different numbers.
4. Logical Operator Programs
Scholarship Eligibility
A student gets a scholarship if:
- Marks ≥ 85 AND
- Attendance ≥ 75%
Otherwise, display "Not Eligible".
Discount Offer
A customer gets a discount if:
- Bill Amount ≥ ₹2000 OR
- Customer is a premium member.
Otherwise, no discount.
Exam Pass/Fail
A student passes if:
- Marks ≥ 40 AND
- Not absent.
If absent, display "Fail due to Absence".
Login Validation
- Username =
"admin"AND Password ="1234"→ Login Success - Username =
"admin"AND Password ≠"1234"→ Wrong Password - Username ≠
"admin"→ Wrong Username
Job Application
Eligible if:
- Qualification = Graduate
- AND (Experience ≥ 2 years OR Age < 25)
Festival Offer
A customer gets a special gift if:
- Shopping Amount ≥ ₹5000
- OR (Premium Member AND Shopping Amount ≥ ₹3000)
Temperature Category
Take the temperature as input and display the appropriate category:
- Above 40 → Very Hot
- 30–40 → Hot
- 20–29 → Normal
- 10–19 → Cold
- Below 10 → Very Cold
Take the number of electricity units consumed as input and display the consumption category:
- 0–100 → Low Consumption
- 101–300 → Medium Consumption
- 301–500 → High Consumption
- Above 500 → Very High Consumption
Salary Category
Take a person's salary as input and display the appropriate category:
- Below ₹20,000 → Low Salary
- ₹20,000–₹50,000 → Average Salary
- ₹50,001–₹1,00,000 → Good Salary
- Above ₹1,00,000 → High Salary
Student Result System
Take marks for five subjects as input.
Perform the following tasks:
- Calculate the total marks.
- Calculate the percentage.
- If the student scores below 33 in any subject, display Fail.
- 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:
- Product price
- Membership status
- Coupon code
Apply the following conditions:
- Apply a discount if the product price is above ₹5,000.
- Apply an additional discount for members.
- Apply another discount if the coupon code is valid.
- 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:
- Age
- Monthly salary
- Credit score
The customer is eligible only if:
- Age is 21 or above.
- Monthly salary is ₹25,000 or above.
- 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:
- Pizza – ₹250
- Burger – ₹150
- Pasta – ₹200
- 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
- Display numbers from:
- 1 to 100
- 100 to 1
- -10 to 10
- 10 to -10
- -10 to -20
- Display even numbers from 1–100.
- Display odd numbers from 32–64.
- Count, calculate the sum, and multiplication of numbers from 1–7.
- Check whether a number is prime.
- Find the factorial of a number.
- Display the multiplication table of a given number.
6. While Loop Programs
- Display numbers for:
- 1 to 100
- 100 to 1
- -10 to 10
- 10 to -10
- -10 to -20
- Display even numbers from 1–100.
- Display odd numbers from 32–64.
- Count, calculate the sum, and multiplication of numbers from 1–7.
- Check whether a number is prime.
- Find the factorial of a number.
- Display the multiplication table of a given number.
- Display digits of a given number.
- Count, calculate the sum, and multiplication of digits.
- Check whether a number is a palindrome.
- Check whether a number is an Armstrong number.
- Check whether a number is a Special number.
7. Do-While Loop Programs
- Display numbers for:
- 1 to 100
- 100 to 1
- -10 to 10
- 10 to -10
- -10 to -20
- Display even numbers from 1–100.
- Display odd numbers from 32–64.
- Count, calculate the sum, and multiplication from 1–7.
- Check whether a number is prime.
- Find the factorial of a number.
- Display the multiplication table of a given number.
8. Nested Loop Programs
- Display all prime numbers from 1–100.
- Display multiplication tables from 1–10.
Pattern Programs
Pattern 1
Pattern 2
Pattern 3
Pattern 4
Pattern 5
Pattern 6
Pattern 7
Pattern 8
Pattern 9
Pattern 10
Pattern 11
Pattern 12
9. Array Programs
- Store and print the following numbers:
- Calculate the count and sum of the array.
- Print only even numbers.
- Print numbers divisible by 5.
- Print numbers divisible by both 5 and 11.
- Print Special numbers.
- Print Palindrome numbers.
- Print Armstrong numbers.
- Find the position and index of
8. - Find the frequency (mode) of
10. - Find the average of the array.
10. Two-Dimensional Array Programs
- Store and display:
- Store and display:
- Display:
- First row
- Second row
- Third row
- First column
- Second column
- Third column
- Left diagonal
- Right diagonal
- Add two matrices.
- Subtract two matrices.
- Find the transpose of a matrix.
11. Functions
- Create a function to display the user's name.
- Create a function to check whether a number is even or odd.
- Create a parameterized function to add a leading
0to a single-digit number. - Create a non-parameterized function to calculate the sum of two numbers.
- Create a function to display numbers from 1–10 using a
whileloop. - Create a function that returns the greater number.
- Create a function that returns all even numbers from the array:
12. Event Handling
- Create a button and display an alert on click.
- Create an
<h1>element and display a console message on click. - Create a button and paragraph with a common click function that displays an alert.
- Create an
<h1>element and button to get the value of the heading. - Create an
<h1>element and button to change the heading text.
13. Form Handling
- Create a form with a Name input and retrieve its value.
- Create a form with a Password input and retrieve its value.
- Create a form with a Date input and retrieve its value.
- Create a form with a Textarea and retrieve its value.
- Create a form with a School dropdown and retrieve its selected value.
- Create a form with an Age (Number) input and retrieve its value.