Experiment 9
Experiment 9
======================================9.1)numberoperations.html=================
<!DOCTYPE html>
<html>
<head>
<title>Number Operations</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input[type="number"] {
padding: 10px;
width: 200px;
margin-right: 10px;
}
button {
padding: 10px 15px;
}
#results {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Number Operations</h1>
<label for="numberInput">Enter a number:</label>
<input type="number" id="numberInput" min="0">
<button onclick="displayResults()">Calculate</button>
<div id="results"></div>
<script>
// Function to calculate the factorial of a number
function factorial(n) {
if (n < 0) return "Factorial is not defined for negative numbers.";
if (n === 0 || n === 1) return 1;
let result = 1;
for (let i = 2; i <= n; i++) {
result *= i;
}
return result;
}
while (a <= n) {
fibSeries.push(a);
let c = a + b;
a = b;
b = c;
}
return fibSeries;
}
// Function to find all prime numbers up to n
function primeNumbers(n) {
if (n < 2) return [];
let primes = [];
</body>
</html>
======================================9.b)updatedfunctions.html===================
<!DOCTYPE html>
<html>
<head>
<title>Number Operations</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input[type="number"] {
padding: 10px;
width: 200px;
margin-right: 10px;
}
button {
padding: 10px 15px;
margin-right: 10px;
}
#results {
margin-top: 20px;
border: 1px solid #ccc;
padding: 15px;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>Number Operations</h1>
<label for="numberInput">Enter a number:</label>
<input type="number" id="numberInput" min="0">
<button onclick="displayFactorial()">Factorial</button>
<button onclick="displayFibonacci()">Fibonacci</button>
<button onclick="displayPrimes()">Prime Numbers</button>
<button onclick="checkPalindrome()">Palindrome</button>
<div id="results"></div>
<script>
// Function to calculate the factorial of a number
function factorial(n) {
if (n < 0) return "Factorial is not defined for negative numbers.";
if (n === 0 || n === 1) return 1;
let result = 1;
for (let i = 2; i <= n; i++) {
result *= i;
}
return result;
}
while (a <= n) {
fibSeries.push(a);
let c = a + b;
a = b;
b = c;
}
return fibSeries;
}
</body>
</html>
===========================================================9.c)registatin2.html====
=============
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
max-width: 400px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="text"],
input[type="tel"],
input[type="email"] {
width: 100%;
padding: 10px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 15px;
cursor: pointer;
}
.error {
color: red;
font-size: 0.9em;
margin-bottom: 10px;
}
.highlight {
border: 1px solid red;
background-color: #ffe6e6;
}
</style>
</head>
<body>
<h2>Registration Form</h2>
<form id="registrationForm">
<label for="name">Name (Starts with alphabet, max 5 characters): </label>
<input type="text" id="name" name="name" required>
<div id="nameError" class="error"></div>
<button type="submit">Register</button>
</form>
<script>
// Function to validate the registration form
document.getElementById('registrationForm').onsubmit = function (event) {
// Prevent form submission
event.preventDefault();
document.getElementById('name').classList.remove('highlight');
document.getElementById('mobile').classList.remove('highlight');
document.getElementById('email').classList.remove('highlight');
// Validate name
const namePattern = /^[A-Za-z][A-Za-z0-9]{0,4}$/; // Starts with an
alphabet, max 5 characters
if (!namePattern.test(name)) {
document.getElementById('nameError').innerHTML = 'Name must start
with an alphabet and be less than 6 characters.';
document.getElementById('name').classList.add('highlight');
valid = false;
}
// Validate mobile
const mobilePattern = /^\d{10}$/; // Exactly 10 digits
if (!mobilePattern.test(mobile)) {
document.getElementById('mobileError').innerHTML = 'Mobile number
must be exactly 10 digits.';
document.getElementById('mobile').classList.add('highlight');
valid = false;
}
// Validate email
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Basic email
validation pattern
if (!emailPattern.test(email)) {
document.getElementById('emailError').innerHTML = 'Please enter a
valid email address.';
document.getElementById('email').classList.add('highlight');
valid = false;
}
</body>
</html>