23BCE0737
C. Manideep Sai
First:-
<!DOCTYPE html>
<html>
<head>
<title>Substrings and Sum of Digits</title>
</head>
<body>
<h1>Generate Substrings and Sum of Digits</h1>
<input type="text" id="inputString" placeholder="Enter a string with
digits">
<button onclick="processString()">Process</button>
<h2>Substrings:</h2>
<p id="substrings"></p>
<h2>Number of Substrings:</h2>
<p id="substringCount"></p>
<h2>Sum of Digits:</h2>
<p id="sumArray"></p>
<h2>Sorted Sum Array:</h2>
<p id="sortedSumArray"></p>
<script>
function processString() {
const input = document.getElementById('inputString').value;
const substrings = [];
const sumArray = [];
for (let i = 0; i < input.length; i++) {
for (let j = i + 1; j <= input.length; j++) {
const substring = input.slice(i, j);
substrings.push(substring);
const sum = substring.split('').reduce((acc, char) => {
if (!isNaN(char) && char !== ' ') {
return acc + parseInt(char);
return acc;
}, 0);
sumArray.push(sum);
document.getElementById('substrings').textContent =
substrings.join(', ');
document.getElementById('substringCount').textContent =
substrings.length;
document.getElementById('sumArray').textContent =
sumArray.join(', ');
const sortedSumArray = sumArray.slice().sort((a, b) => a - b);
document.getElementById('sortedSumArray').textContent =
sortedSumArray.join(', ');
</script>
</body>
</html>
Second:-
<!DOCTYPE html>
<html>
<head>
<title>Count and Replace Symbols</title>
</head>
<body>
<h1>Count and Replace Special Symbols</h1>
<input type="text" id="inputString" placeholder="Enter a string">
<button onclick="processString()">Process</button>
<h2>Counts:</h2>
<p>Alphabets: <span id="alphabetCount"></span></p>
<p>Digits: <span id="digitCount"></span></p>
<p>Special Symbols: <span id="symbolCount"></span></p>
<h2>Modified String:</h2>
<p id="modifiedString"></p>
<script>
function processString() {
const input = document.getElementById('inputString').value;
let alphabetCount = 0;
let digitCount = 0;
let symbolCount = 0;
let modifiedString = '';
for (let char of input) {
if (/[a-zA-Z]/.test(char)) {
alphabetCount++;
modifiedString += char;
} else if (/\d/.test(char)) {
digitCount++;
modifiedString += char;
} else if (char === ' ') {
modifiedString += char; // Keep spaces as is
} else {
symbolCount++;
modifiedString += 'SS'; // Replace special symbols with 'SS'
document.getElementById('alphabetCount').textContent =
alphabetCount;
document.getElementById('digitCount').textContent = digitCount;
document.getElementById('symbolCount').textContent =
symbolCount;
document.getElementById('modifiedString').textContent =
modifiedString;
</script>
</body>
</html>
Third:-
<!DOCTYPE html>
<html>
<head>
<title>Character Count and Case Swap</title>
</head>
<body>
<h1>Character Count and Case Swap</h1>
<input type="text" id="inputString" placeholder="Enter a string">
<button onclick="processString()">Process</button>
<h2>Character Counts:</h2>
<p id="characterCounts"></p>
<h2>Number of Unique Characters:</h2>
<p id="uniqueCount"></p>
<h2>Case Swapped String:</h2>
<p id="caseSwappedString"></p>
<script>
function processString() {
const input = document.getElementById('inputString').value;
const charCount = {};
let uniqueCount = 0;
let caseSwappedString = '';
for (let char of input) {
if (charCount[char]) {
charCount[char]++;
} else {
charCount[char] = 1;
uniqueCount++;
if (/[a-z]/.test(char)) {
caseSwappedString += char.toUpperCase();
} else if (/[A-Z]/.test(char)) {
caseSwappedString += char.toLowerCase();
} else {
caseSwappedString += char;
let countsOutput = '';
for (let char in charCount) {
countsOutput += `'${char}': ${charCount[char]}<br>`;
document.getElementById('characterCounts').innerHTML =
countsOutput;
document.getElementById('uniqueCount').textContent =
uniqueCount;
document.getElementById('caseSwappedString').textContent =
caseSwappedString;
</script>
</body>
</html>
Fourth:-
<!DOCTYPE html>
<html>
<head>
<title>Happy Numbers</title>
</head>
<body>
<h1>Happy Numbers Generator</h1>
<label for="start">Starting Number:</label>
<input type="number" id="start" placeholder="Enter starting
number">
<br><br>
<label for="end">Ending Number:</label>
<input type="number" id="end" placeholder="Enter ending number">
<br><br>
<button onclick="findHappyNumbers()">Find Happy
Numbers</button>
<h2>Happy Numbers:</h2>
<p id="happyNumbers"></p>
<script>
function isHappyNumber(n) {
let seen = new Set();
while (n !== 1 && !seen.has(n)) {
seen.add(n);
n = String(n).split('').reduce((sum, digit) => sum +
Math.pow(Number(digit), 2), 0);
return n === 1;
function findHappyNumbers() {
const start = parseInt(document.getElementById('start').value);
const end = parseInt(document.getElementById('end').value);
const happyNumbers = [];
for (let i = start; i <= end; i++) {
if (isHappyNumber(i)) {
happyNumbers.push(i);
document.getElementById('happyNumbers').textContent =
happyNumbers.join(', ');
</script>
</body>
</html>
FIFTH:-
<!DOCTYPE html>
<html>
<head>
<title>Text Analysis</title>
</head>
<body>
<h1>Text Analysis</h1>
<textarea id="inputText" rows="10" cols="50" placeholder="Enter
your text here"></textarea>
<br><br>
<button onclick="analyzeText()">Analyze Text</button>
<h2>Analysis Results:</h2>
<p>Consonants: <span id="consonantCount"></span></p>
<p>Vowels: <span id="vowelCount"></span></p>
<p>Spaces: <span id="spaceCount"></span></p>
<p>Words: <span id="wordCount"></span></p>
<p>Special Symbols: <span id="symbolCount"></span></p>
<h2>Array of Strings (Length 5):</h2>
<p id="stringArray"></p>
<script>
function analyzeText() {
const text = document.getElementById('inputText').value;
let consonantCount = 0;
let vowelCount = 0;
let spaceCount = 0;
let wordCount = 0;
let symbolCount = 0;
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const consonants = new
Set('bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ');
for (let char of text) {
if (vowels.has(char.toLowerCase())) {
vowelCount++;
} else if (consonants.has(char)) {
consonantCount++;
} else if (char === ' ') {
spaceCount++;
} else if (/[^a-zA-Z0-9\s]/.test(char)) {
symbolCount++;
}
wordCount = text.split(/\s+/).filter(word => word.length >
0).length;
const words = text.split(/\s+/).filter(word => word.length > 0);
const stringArray = [];
for (let i = 0; i < words.length; i++) {
if (words[i].length >= 5) {
stringArray.push(words[i].substring(0, 5));
document.getElementById('consonantCount').textContent =
consonantCount;
document.getElementById('vowelCount').textContent =
vowelCount;
document.getElementById('spaceCount').textContent =
spaceCount;
document.getElementById('wordCount').textContent = wordCount;
document.getElementById('symbolCount').textContent =
symbolCount;
document.getElementById('stringArray').textContent =
JSON.stringify(stringArray);
</script>
</body>
</html>
SIXTH:-
<!DOCTYPE html>
<html>
<head>
<title>Swap Nearby Floats</title>
</head>
<body>
<input type="text" id="inputArray" placeholder="Enter comma-
separated floats">
<button onclick="swapElements()">Swap</button>
<p id="output"></p>
<script>
function swapElements() {
let input = document.getElementById("inputArray").value;
let arr = input.split(",").map(Number);
for (let i = 0; i < arr.length - 1; i += 2) {
[arr[i], arr[i + 1]] = [arr[i + 1], arr[i]];
document.getElementById("output").innerText = "Swapped Array:
[" + arr.join(", ") + "]";
</script>
</body>
</html>
Seventh:-
<!DOCTYPE html>
<html>
<head>
<title>Matrix Symmetry Check</title>
</head>
<body>
<textarea id="inputMatrix" placeholder="Enter matrix row by row,
comma-separated"></textarea>
<button onclick="checkSymmetry()">Check Symmetry</button>
<p id="output"></p>
<script>
function checkSymmetry() {
let input =
document.getElementById("inputMatrix").value.trim().split("\n").map(row
=> row.split(",").map(Number));
let n = input.length;
for (let i = 0; i < n; i++) {
if (input[i].length !== n) {
document.getElementById("output").innerText = "Matrix is
not square!";
return;
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (input[i][j] !== input[j][i]) {
document.getElementById("output").innerText = "Matrix is
not symmetric";
return;
}
}
document.getElementById("output").innerText = "Matrix is
symmetric";
</script>
</body>
</html>
Eighth:-
<!DOCTYPE html>
<html>
<head>
<title>Matrix Symmetry Check</title>
</head>
<body>
<h1>Matrix Symmetry Check</h1>
<textarea id="inputMatrix" rows="5" cols="30" placeholder="Enter
matrix row by row, comma-separated"></textarea>
<br><br>
<button onclick="checkSymmetry()">Check Symmetry</button>
<p id="output"></p>
<script>
function checkSymmetry() {
const input =
document.getElementById("inputMatrix").value.trim();
if (!input) {
document.getElementById("output").innerText = "Please enter a
matrix.";
return;
let rows = input.split("\n");
let matrix = [];
let isValid = true;
for (let i = 0; i < rows.length; i++) {
let row = rows[i].split(",");
matrix[i] = [];
for (let j = 0; j < row.length; j++) {
let num = Number(row[j].trim());
if (isNaN(num)) {
isValid = false;
break;
matrix[i][j] = num;
if (!isValid) break;
if (!isValid) {
document.getElementById("output").innerText = "Invalid input.
Please enter a valid matrix with numbers.";
return;
const n = matrix.length;
if (!matrix.every(row => row.length === n)) {
document.getElementById("output").innerText = "Matrix is not
square!";
return;
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (matrix[i][j] !== matrix[j][i]) {
document.getElementById("output").innerText = "Matrix is
not symmetric.";
return;
document.getElementById("output").innerText = "Matrix is
symmetric.";
</script>
</body>
</html>
NINTH:-
<!DOCTYPE html>
<html>
<head>
<title>Age Alert</title>
</head>
<body>
<label for="user1">User 1 Name:</label>
<input type="text" id="user1" placeholder="Enter name"><br>
<label for="dob1">User 1 DOB:</label>
<input type="date" id="dob1"><br>
<label for="user2">User 2 Name:</label>
<input type="text" id="user2" placeholder="Enter name"><br>
<label for="dob2">User 2 DOB:</label>
<input type="date" id="dob2"><br>
<button onclick="checkAge()">Check Age</button>
<script>
function calculateAge(dob) {
let birthDate = new Date(dob);
let diff = Date.now() - birthDate.getTime();
let ageDate = new Date(diff);
return Math.abs(ageDate.getUTCFullYear() - 1970);
function checkAge() {
let name1 = document.getElementById('user1').value;
let dob1 = document.getElementById('dob1').value;
let name2 = document.getElementById('user2').value;
let dob2 = document.getElementById('dob2').value;
let age1 = calculateAge(dob1);
let age2 = calculateAge(dob2);
let younger, youngerAge, ageDiff;
if (age1 < age2) {
younger = name1;
youngerAge = age1;
ageDiff = age2 - age1;
} else {
younger = name2;
youngerAge = age2;
ageDiff = age1 - age2;
alert(youngerAge + ' - ' + younger + ", you are younger by " +
ageDiff + " years!");
</script>
</body>
</html>
TENTH:-
<!DOCTYPE html>
<html>
<head>
<title>Perfect Squares</title>
</head>
<body>
<label for="start">Start:</label>
<input type="number" id="start">
<label for="end">End:</label>
<input type="number" id="end">
<button onclick="findPerfectSquares()">Generate</button>
<p id="result"></p>
<script>
function findPerfectSquares() {
let start = parseInt(document.getElementById('start').value);
let end = parseInt(document.getElementById('end').value);
let squares = [];
for (let i = Math.ceil(Math.sqrt(start)); i <=
Math.floor(Math.sqrt(end)); i++) {
squares.push(i * i);
document.getElementById('result').textContent = squares.join(', ');
</script>
</body>
</html>