JAVA SCRIPT Tushar Singh
JAVA SCRIPT Tushar Singh
Q1. Create a function called calculateGrade that takes a student's score as input and returns their
grade according to the following criteria: o 90-100: 'A' o 80-89: 'B' o 70-79: 'C' o 60-69: 'D' o Below
60: 'F'.
Program:-
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grade Calculator</title>
<style> body { font-family: Arial,
sans-serif; text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
.container
{ background:
white; padding:
20px; border-radius:
10px;
box-shadow: 0 0 10px rgba(0, 0, 0,
0.2); width: 300px; margin: auto;
}
input, button { margin:
10px; padding: 10px;
font-size: 16px;
width: 80%; border:
1px solid #ccc;
border-radius: 5px;
} button { background-color:
#28a745;
color: white; cursor:
pointer;
} button:hover { background-
color: #218838;
}
#result { font-
size: 18px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Student Grade Calculator</h2>
1
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Output:-
Q2. Write a function that takes an array of numbers and returns both the minimum and maximum
values in the array. Don't use Math.min() or Math.max().
Program:-
<!DOCTYPE html>
<head>
2
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Find Min & Max in Array</title>
<style> body { font-family: Arial,
sans-serif; text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
.container
{ background:
white; padding:
20px; width: 350px;
margin: auto;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
input, button { margin:
10px; padding: 10px;
font-size: 16px;
width: 90%; border-
radius: 5px; border:
1px solid #ccc;
} button { background-color:
#007bff;
color: white; cursor:
pointer;
} button:hover { background-
color: #0056b3;
}
.result { font-size:
18px; font-
weight: bold;
margin-top:
10px;
}
</style>
</head>
<body>
<div class="container">
<h2>🔢 Find Min & Max in Array</h2>
<label for="numbers">Enter Numbers (comma-separated):</label>
<input type="text" id="numbers" placeholder="e.g., 5, 12, -3, 8, 99">
<button onclick="findMinMax()">Find Min & Max</button>
<p class="result" id="result"></p>
</div>
3
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Output:-
Q3. Create a function that accepts a string and returns a new string with the first letter of each word
capitalized. For example: "hello world" should return "Hello World".
Program:- <!
DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Capitalize Words</title>
<style> body { font-family: Arial,
sans-serif; text-align: center;
margin: 50px;
4
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
background-color: #f4f4f4;
}
.container { background: white; padding:
20px; width: 350px; margin: auto; border-
radius: 10px; box-shadow: 0px 0px 10px
rgba(0, 0, 0, 0.2);
}
input, button {
margin: 10px;
padding: 10px; font-
size: 16px; width:
90%; border-radius:
5px; border: 1px solid
#ccc;
}
button {
background-color:
#007bff; color: white;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.result { font-size:
18px; font-
weight: bold;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>🔠 Capitalize Each Word</h2>
<label for="text">Enter a Sentence:</label>
<input type="text" id="text" placeholder="e.g., hello world">
<button onclick="capitalizeInput()">Capitalize</button>
<p class="result" id="result"></p>
</div> <script> function
capitalizeWords(str) { return
str
.split(" ") // Split string into words
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize first letter .join("
"); // Join words back into a string
5
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
}
function capitalizeInput() { let input =
document.getElementById("text").value.trim(); if (input
=== "") {
document.getElementById("result").innerHTML = "❌ Please enter a sentence!";
document.getElementById("result").style.color = "red"; return;
}
let capitalizedText = capitalizeWords(input); document.getElementById("result").innerHTML
= `✅ Capitalized: <b>${capitalizedText}</b>`; document.getElementById("result").style.color
= "black";
}
</script>
</body>
</html>
Output:-
Q4. Write a function that determines whether a given year is a leap year. A leap year is divisible by 4,
but not by 100 unless it's also divisible by 400.
Program:-
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leap Year Checker</title>
<style> body { font-family: Arial,
sans-serif; text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
6
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
.container
{ background:
white; padding:
20px; width: 350px;
margin: auto;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
input, button { margin:
10px; padding: 10px;
font-size: 16px;
width: 90%; border-
radius: 5px; border:
1px solid #ccc;
} button { background-color:
#007bff;
color: white; cursor:
pointer;
} button:hover { background-
color: #0056b3;
}
.result { font-size:
18px; font-
weight: bold;
margin-top:
10px;
}
</style>
</head>
<body>
<div class="container">
<h2>🌍 Leap Year Checker</h2>
<label for="year">Enter a Year:</label>
<input type="number" id="year" placeholder="e.g., 2024">
<button onclick="checkLeapYear()">Check Leap Year</button>
<p class="result" id="result"></p>
</div>
<script> function isLeapYear(year) { return (year % 4 === 0 && year %
100 !== 0) || (year % 400 === 0);
}
function checkLeapYear() { let year =
document.getElementById("year").value.trim(); let
resultElement = document.getElementById("result"); if (year
=== "" || isNaN(year)) { resultElement.innerHTML = "❌
Please enter a valid year!";
resultElement.style.color = "red";
7
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Output:-
Q5. Create a function that counts how many vowels are in a string. Consider 'a', 'e', 'i', 'o', and 'u' as
vowels.
Program:-
<!DOCTYPE html>
8
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vowel & Consonant Counter</title>
<style> body { font-family: Arial,
sans-serif; text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
.container { background: white; padding:
20px; width: 350px; margin: auto; border-
radius: 10px; box-shadow: 0px 0px 10px
rgba(0, 0, 0, 0.2);
}
input, button {
margin: 10px;
padding: 10px; font-
size: 16px; width:
90%; border-radius:
5px; border: 1px solid
#ccc;
}
button {
background-color:
#007bff; color: white;
cursor: pointer; transition:
0.3s;
}
button:hover {
background-color: #0056b3;
}
.result { font-size:
18px; font-
weight: bold;
margin-top: 10px;
}
.highlight { color:
#ff5733; font-
weight: bold;
}
</style>
</head>
<body>
9
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
<div class="container">
<h2>🔤 Vowel & Consonant Counter</h2>
<label for="text">Enter a String:</label>
<input type="text" id="text" placeholder="e.g., hello world">
<button onclick="countCharacters()">Analyze Text</button>
<p class="result" id="result"></p>
</div>
<script> function
countCharacters() {
let input =
document.getElementById("text").value.trim(); let
resultElement = document.getElementById("result"); if
(input === "") {
resultElement.innerHTML = "❌ Please enter a valid string!";
resultElement.style.color = "red"; return;
}
let vowels = input.match(/[aeiouAEIOU]/g) || []; let consonants =
input.match(/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]/g) || []; let vowelCount
= vowels.length; let consonantCount = consonants.length; let highlightedVowels =
input.replace(/([aeiouAEIOU])/g, '<span
class="highlight">$1</span>');
resultElement.innerHTML = `
✅ Vowel Count: <b>${vowelCount}</b> <br>
🔤 Consonant Count: <b>${consonantCount}</b> <br>
✨ Highlighted Vowels: <br> ${highlightedVowels}
`;
resultElement.style.color = "black";
}
</script>
</body>
</html>
Output:-
10
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
11
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Program:- <!
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vowel & Consonant Counter</title>
<style>
body {
font-family: Arial, sans-
serif; text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
.container { background: white; padding:
20px; width: 350px; margin: auto; border-
radius: 10px; box-shadow: 0px 0px 10px
rgba(0, 0, 0, 0.2);
}
input, button { margin:
10px; padding: 10px;
font-size: 16px; width:
90%; border-radius:
5px; border: 1px solid
#ccc;
}
button {
background-color:
#007bff; color: white;
cursor: pointer; transition:
0.3s;
}
button:hover {
background-color: #0056b3;
}
.result { font-size:
18px; font-
12
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
weight: bold;
margin-top: 10px;
}
.highlight { color:
#ff5733; font-
weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h2>🔤 Vowel & Consonant Counter</h2>
<label for="text">Enter a String:</label>
<input type="text" id="text" placeholder="e.g., hello world">
<button onclick="countCharacters()">Analyze Text</button>
<p class="result" id="result"></p>
</div>
<script> function
countCharacters() {
let input =
document.getElementById("text").value.trim(); let
resultElement = document.getElementById("result"); if
(input === "") {
resultElement.innerHTML = "❌ Please enter a valid string!";
resultElement.style.color = "red"; return;
}
let vowels = input.match(/[aeiouAEIOU]/g) || []; let consonants =
input.match(/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]/g) || []; let vowelCount
= vowels.length; let consonantCount = consonants.length; let highlightedVowels =
input.replace(/([aeiouAEIOU])/g, '<span
class="highlight">$1</span>');
resultElement.innerHTML = `
✅ Vowel Count: <b>${vowelCount}</b> <br>
🔤 Consonant Count: <b>${consonantCount}</b> <br>
✨ Highlighted Vowels: <br> ${highlightedVowels}
`;
resultElement.style.color = "black";
}
</script>
</body> </html>
Output:-
13
NAME: Tushar Singh PRN No: ADT24MGTM0993
DIV: C CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
14
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Program:- <!
DOCTYPE html>
15
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rectangle Calculator</title>
<style>
/* General Styling */
body {
font-family: 'Poppins', sans-serif; text-align: center;
margin: 0; padding: 0; background: linear-
gradient(135deg, #1e3c72, #2a5298); color: white;
overflow: hidden;
}
/* Container Styling */
.container { background: linear-gradient(135deg, #ffffff, #e3e3e3);
padding: 30px; width: 400px; margin: 50px auto; border-radius:
12px; box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.3); text-align:
center; color: #333; transition: transform 0.3s ease-in-out, box-
shadow 0.3s ease-in-out; animation: fadeIn 1s ease-in-out;
}
/* Hover Animation */
.container:hover { transform: scale(1.03); box-
shadow: 0px 15px 25px rgba(0, 0, 0, 0.4);
}
/* Title Styling */
h2 {
color: #007bff; font-size:
24px;
}
/* Input Fields */
input {
margin: 10px; padding: 12px;
font-size: 16px; width: 90%;
border-radius: 8px; border:
1px solid #ccc; transition: all
0.3s ease-in-out;
}
/* Input Focus Effect */
input:focus {
border-color: #007bff; outline: none; box-
shadow: 0px 0px 8px rgba(0, 123, 255, 0.5);
}
16
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
/* Buttons */
button {
margin: 10px; padding: 12px;
font-size: 16px; width: 95%;
border-radius: 8px; border:
none; cursor: pointer;
transition: all 0.3s ease-in-
out; font-weight: bold;
}
/* Button Colors */
.btn-calculate { background: linear-gradient(45deg,
#28a745, #218838); color: white; box-shadow: 0px 4px
10px rgba(40, 167, 69, 0.5);
}
/* Button Hover Effects */ button:hover
{
opacity: 0.9; transform:
translateY(-2px);
box-shadow: 0px 6px 15px rgba(0, 0, 0, 0.3);
}
/* Result Styling */
17
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
18
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Output:-
19
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Program:- <!
DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Score Tracker</title>
<style>
body {
font-family: 'Poppins', sans-serif; text-align: center;
margin: 0; padding: 0; background: linear-
gradient(135deg, #2c3e50, #4ca1af); color: white;
}
.container { background: white; padding:
25px; width: 400px; margin: 50px auto;
border-radius: 12px; box-shadow: 0px
5px 15px rgba(0, 0, 0, 0.3); text-align:
center; color: #333; transition: transform
0.3s ease-in-out;
20
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
}
.container:hover
{ transform: scale(1.02);
}
h2 {
color: #007bff;
}
input {
margin:
10px;
padding:
12px; font-
size: 16px;
width: 90%;
border-
radius: 8px;
border: 1px
solid #ccc;
transition:
0.3s;
}
input:focus {
border-color: #007bff;
outline: none;
}
button {
margin: 10px;
padding: 12px;
font-size: 16px;
width: 95%;
border-radius:
8px; border:
none; cursor:
pointer;
transition: 0.3s;
}
21
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
.btn-add { background-
color: #28a745; color:
white;
}
.btn-reset { background-
color: #dc3545; color:
white;
}
button:hover {
opacity: 0.8;
}
.result { font-size:
18px; font-
weight: bold;
margin-top:
15px;
}
</style>
</head>
<body>
<div class="container">
<h2>➵ Student Score Tracker</h2>
<label for="name">Student Name:</label>
<input type="text" id="name" placeholder="Enter student name">
<label for="score">Enter Score:</label>
<input type="number" id="score" placeholder="e.g., 85">
<button class="btn-add" onclick="addStudentScore()">Add Score</button>
<button class="btn-reset" onclick="resetStudent()">Reset</button>
<p class="result" id="result"></p>
</div>
<script> class
Student {
constructor(name
) { this.name =
name;
this.scores = [];
}
addScore(score) {
22
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
23
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
function resetStudent() {
document.getElementById("name").value = "";
document.getElementById("score").value = "";
document.getElementById("result").innerHTML =
""; student = null;
}
</script>
</body>
</html>
Output:-
24
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Program:-
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Digital Clock</title>
25
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
<style>
body {
font-family: 'Poppins', sans-
serif; text-align: center;
margin: 0; padding: 0;
background: linear-gradient(135deg, #2c3e50,
#4ca1af); color: white; display: flex; justify-content:
center; align-items: center; height: 100vh;
}
.clock-container
{ background:
white; padding:
30px; border-
radius: 12px;
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
transition: transform 0.3s ease-in-out;
}
.clock-container:hover
{ transform: scale(1.05);
}
h
2
{
color: #007bff;
margin-bottom: 10px;
}
.clock { font-size:
2rem; font-
weight: bold;
margin: 10px 0;
}
.toggle-button { margin-
top: 10px; padding:
10px 20px; font-size:
16px; border: none;
border-radius: 8px;
cursor: pointer;
background-color:
#28a745;
26
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
color: white;
transition: 0.3s;
}
.toggle-button:hover
{ opacity: 0.8;
}
</style>
</head>
<body>
<div class="clock-container">
<h2> Live Digital Clock</h2>
<div class="clock" id="clock">--: ---- </div>
<button class="toggle-button" onclick="toggleFormat()">Switch to 12-hour format</button>
</div>
<script> class Clock { constructor()
{ this.use24HourFormat = true; // Default format
} getTime() { const now = new
Date(); let hours =
now.getHours(); let minutes =
now.getMinutes(); let seconds =
now.getSeconds();
27
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Output:-
28
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
Program:-
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Library Management System</title>
<style> body { font-family:
'Poppins', sans-serif; text-align:
center; margin: 0; padding: 0;
background: linear-gradient(135deg, #2c3e50, #4ca1af);
color: white;
}
.library-container
{ background:
white; padding:
25px; width:
450px; margin:
50px auto;
border-radius:
12px;
box-shadow: 0px 5px 15px rgba(0, 0, 0,
0.3); text-align: center; color: #333;
transition: transform 0.3s ease-in-out;
}
.library-container:hover
{ transform: scale(1.02);
} h2 { color:
#007bff;
} input { margin:
10px; padding: 12px;
font-size: 16px; width:
90%; border-radius:
8px; border: 1px solid
#ccc; transition: 0.3s;
} input:focus
{ border-color:
#007bff; outline:
none;
}
butto
n{
29
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
margin: 10px;
padding: 12px;
font-size: 16px;
width: 95%;
border-radius:
8px; border:
none; cursor:
pointer;
transition: 0.3s;
}
background:
#f8f9fa; padding:
10px; margin: 5px
0; border-radius:
5px;
}
</style>
</head>
<body>
<div class="library-container">
<h2>📚 Library Management System</h2>
<label for="bookName">Book Title:</label>
<input type="text" id="bookName" placeholder="Enter book title">
<button class="btn-add" onclick="addBook()">Add Book</button>
30
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
31
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
this.availableBooks.push(book);
this.updateUI();
}
} updateUI() { let availableList =
document.getElementById("availableBooks"); let checkedOutList =
document.getElementById("checkedOutBooks");
availableList.innerHTML = this.availableBooks.map(book =>
`<li>${book}</li>`).join(""); checkedOutList.innerHTML = this.checkedOutBooks.map(book =>
`<li>${book}</li>`).join("");
}
}
const library = new Library();
32
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
document.getElementById("bookName").value = "";
}
}
</script>
</body>
</html>
Output:-
33
NAME: Manthan Surkar PRN No: ADT24MGTM0946
DIV: B CLASS: MCA-I Sem-II (DS)
Subject: Web Technologies Date:12/03/2025
34