Endterm Final Print
Endterm Final Print
Problem Statement :- 1 Write a javascript code to change the color of text according to user choice from the drop
down list with color names.
Algorithm:-
1. Create a dropdown list with color options.
2. Add an element (e.g., a paragraph) whose text color will be changed.
3. Create a function (changeTextColor) that is triggered when the user selects a color from the
dropdown.
4. Get the selected color from the dropdown.
5. Change the text color of the element using the selected color.
Code and output
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Color Changer</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<br>
<br>
<h1>Select a Color</h1>
<h2 id="akt">Anukalp Kumar thakur MCA 1st C-21 (1102699)</h2>
<option value="orange">Orange</option>
<option value="purple">Purple</option>
<option value="black">Black</option>
<option value="yellow">yellow</option>
</select>
<script>
function changeTextColor() {
// Get the selected color from the dropdown
var selectedColor = document.getElementById("colorSelector").value;
</body>
</html>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem Statement:-2 Write a javascript code to sort an array taken as input from the user
Algorithm
1. Start
3. Prompt the user to enter the length of the array and store it in a variable (let's call it 'length').
6. Use a sorting algorithm (e.g., bubble sort, quicksort, mergesort) to sort the array.
8. End
Code and output
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array Sorter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
#m
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
{color: green;}
#a
{color: purple;
}
}
</style>
</head>
<body>
<br>
<br>
<h1>Array Sorter by </h1>
<h2 id="a">Anukalp Kumar Thakur<h2>
<p id="m">Enter numbers separated by commas:</p>
<input type="text" id="inputArray" placeholder="e.g., 5, 3, 8, 1">
<button onclick="sortArray()">Sort</button>
<p id="sortedArray"></p>
<script>
function sortArray() {
// Get the input array from the user
var inputArrayString = document.getElementById("inputArray").value;
inputArray.sort(function(a, b) {
return a - b; // For numeric sorting
});
</body>
</html>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem Statement:-3 :-Write a javascript code to validate registration form input fields.
1. Start
5. End
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem Statement:- 4- Write a javascript code to create a text content with welcome message in red color on
button click. Take username as input.
Algorithm:
1. Start
d. Display the welcome message in a specific element (e.g., a paragraph) in red color.
6. End
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem statement:- 5 - Write a javascript code to find whether a given string is ‘Snowball String’ or not. A
snowball string is one, whose length of each word, are in ascending order and consecutive too. for example- "I am
the king" length of I=1 am =2 the=3 king
Algorithm:-
1. Start
ii. Check if the length is greater than the length of the previous word (if not the first word).
- If not, return false.
4. End
Code and output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Snowball String Checker</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
margin: 50px;
}
</style>
</head>
<body>
<button onclick="checkSnowballString()">Check</button>
<p id="result"></p>
<script>
function checkSnowballString() {
// Get the input string
var inputString = document.getElementById("inputString").value.trim();
</body>
</html>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
PHP
Problem statement :- 6 - Write a PHP script to display the prime numbers from 1-100.
Algorithm
1. Start local host for running php code, I am using WAMP server for this having port no 3306
4. End
Code and output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prime Numbers</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
</head>
<body>
<?php
function isPrime($number) {
if ($number <= 1) {
return false;
}
return true;
}
echo "<p>";
for ($i = 1; $i <= 100; $i++) {
if (isPrime($i)) {
echo $i . " ";
}
}
echo "</p>";
?>
</body>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
</html>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
1. Start
2. Create a function (e.g., searchDigit) that takes two parameters - the number and the digit to search. a.
Convert the number to a string for easier digit manipulation. b. Loop through each digit in the string:
i. If the current digit matches the search digit, return true. c. If the loop completes without finding the
digit, return false.3. Take input from the user for the number and digit.
4. Call the searchDigit function with the provided number and digit.5. Display whether the digit is found
or not.
6. End
Code and Output:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digit Search</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<h1>Digit Search</h1>
<form method="post">
<label for="number"> Enter a number :</label>
<input type="number" name="number" required>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
<br>
<br>
<button type="submit">Search</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the input values
$number = $_POST["number"];
$digit = $_POST["digit"];
</body>
</html>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem statement-8- . Design an associative, array in PHP, with ‘Course’ as key and ‘Semester’ as
value and perform following operations (using predefined functions): i) Sort this array with respect to the
key, in ascending order. ii) Sort this array with respect to the value, in descending order.
Algorithm
1. Start
7. End
Code and Output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Associative Array Operations</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
}
</style>
</head>
<body>
<h1>Associative Array Operations</h1>
<?php
// Create an associative array
$courses = array(
'Math' => 'First',
'Physics' => 'Second',
'Chemistry' => 'Third',
'Biology' => 'First',
'History' => 'Second'
);
// Display the original array
echo "<p>Original Array:</p>";
printArray($courses);
// Sort array with respect to the key in ascending order
ksort($courses);
echo "<p>Array Sorted by Key (Ascending Order):</p>";
printArray($courses);
// Sort array with respect to the value in descending order
arsort($courses);
echo "<p>Array Sorted by Value (Descending Order):</p>";
printArray($courses);
?>
</body>
</html>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem statement :- 9 – Write a PHP script to sort strings using user defined functions.
Algorithm
1. Start
2. Create a function (e.g., customSort) that takes an array of strings as input.
a. Implement a sorting algorithm within this function.
b. The sorting algorithm can be any user-defined logic based on string comparison.
3. Take an array of strings as input from the user.
4. Call the customSort function with the array of strings.
5. Display the sorted array.
6. End
Code and Output
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Replacement</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<h1>String Replacement</h1>
<?php
// Original string
$originalString = "This is a sample string. It demonstrates how 'is' is replaced.";
// Find occurrences of 'is' and replace with 'and'
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Problem Statement:- 10- Write a PHP script that will give the following Validations on an HTML form :
i) The name field should not be left blank.
ii) The name field should not contain numbers and special characters.
iii) Course can only be ‘MCA’, ‘BCA’ and ‘BTECH’.
iv) Email should contain ‘@’ and ‘.’ symbol.
Algorithm
1. Start
3. On form submission:
a. Retrieve the values entered by the user for name, course, and email.
f. If all validations pass, you can submit the form or perform further actions.
4. End
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
Final Assignment
Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>College Application Form</title>
<style>
body {
background-image: url("geu.png");
background-color: lightgray;
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 400px;
}
form {
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
display: flex;
flex-direction: column;
}
label {
margin-bottom: 8px;
font-weight: bold;
}
input, textarea {
padding: 10px;
margin-bottom: 15px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.error {
color: red;
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
}
</style>
</head>
<body>
<div class="container">
<h2>College Application Form</h2>
<form action="form.php" method="post" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<span id="nameError" class="error"></span>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<span id="emailError" class="error"></span>
<label for="address">Address:</label>
<textarea id="address" name="address" rows="2" required></textarea>
<span id="addressError" class="error"></span>
<button type="submit">Submit</button>
<br><br>
<button onclick="redirectToLink()">Home</button>
<br><br>
<button onclick="redirectTologin()">Login</button>
<script>
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
function redirectToLink() {
window.location.href = 'https://geu.ac.in';
}
function redirectTologin() {
window.location.href = 'loginform from mainpage.html';
}
function validateForm() {
// Get the values from the input fields
var name = document.getElementById('name').value.trim();
var email = document.getElementById('email').value.trim();
var mobile = document.getElementById('mobile').value.trim();
var address = document.getElementById('address').value.trim();
// Validate name
if (name.length < 5) {
document.getElementById('nameError').innerText = 'Name must be at least 5 characters.';
return false;
} else {
document.getElementById('nameError').innerText = '';
}
// Validate email
if (email.length < 5) {
document.getElementById('emailError').innerText = 'Email must be at least 5 characters.';
return false;
} else {
document.getElementById('emailError').innerText = '';
}
// Validate mobile
if (mobile.length !== 10) {
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
// Validate address
if (address.length < 8) {
document.getElementById('addressError').innerText = 'Address should be at least 8 characters.';
return false;
} else {
document.getElementById('addressError').innerText = '';
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
Anukalp kumar Thakur MCA-C 1st sem Roll 21 (1102699)
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}