assignment6 webd
assignment6 webd
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Form Validation</title>
<script>
function validateForm(e) {
e.preventDefault();
const name = document.getElementById("name").value;
if (name.length < 2) {
alert("Name must be at least 2 characters long.");
return false;
}
console.log("Name:", name);
console.log("Email:", email);
console.log("Password:", password);
console.log("Age:", age);
}
</script>
</head>
<body>
<h2>Registration Form</h2>
<form id="registrationForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br><br>
<button type="submit">Submit</button>
</form>
<script>
document.getElementById("registrationForm").addEventListener("submit",
validateForm);
</script>
</body>
</html>
Table
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Create Table with innerHTML</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 10px;
text-align: center;
}
</style>
<script>
function createTable() {
const data = [
{ name: "John", age: 28, country: "USA" },
{ name: "Sara", age: 24, country: "UK" },
{ name: "Carlos", age: 32, country: "Mexico" },
{ name: "Mia", age: 25, country: "Canada" }
];
tableHTML += "<tr>";
tableHTML += "<th>Name</th><th>Age</th><th>Country</th>";
tableHTML += "</tr>";
data.forEach(item => {
tableHTML += "<tr>";
tableHTML += `<td>${item.name}</td>`;
tableHTML += `<td>${item.age}</td>`;
tableHTML += `<td>${item.country}</td>`;
tableHTML += "</tr>";
});
tableHTML += "</table>";
document.getElementById("tableContainer").innerHTML =
tableHTML;
}
</script>
</head>
<body>
</body>
</html>
Array
fruits.push("Fig");
console.log( fruits);
fruits.reverse();
console.log("After reverse():", fruits);
<script>
let person = {
name: "John Doe",
id: "P12345",
age: 30,
gender: "Male",
salary: 50000, displayALL: function() {
console.log("Person Details:");
console.log("Name: " + this.name);
console.log("ID: " + this.id);
console.log("Age: " + this.age);
console.log("Gender: " + this.gender);
console.log("Salary: $" + this.salary);
}
};
person.displayALL();
</script>
</body>
</html>