Av SC U4aie23153

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

NAME:T.

Rahul Satya Dev

ROLL NO:AV.SC.U4AIE23153

CLASS:AIE

SECTION:B

1. write a Java script to determine whether the user is eligible enter to the pub or not.

CODE:
<!DOCTYPE html>

<head>

<title>Pub Entry Check</title>

<script>

function checkEligibility() {

age = prompt("Please enter your age:");

age = parseInt(age);

if (isNaN(age)) {

document.write("Please enter a valid number for age.");

} else {

if (age >= 18) {

document.write("You are eligible to enter the pub.");

} else {

document.write("You are not eligible to enter the pub.");

</script>

</head>

<body>

<h1>Pub Entry Eligibility Checker</h1>

<button onclick="checkEligibility()">Check Eligibility</button>

</body>

</html>
OUTPUT:

2.write a Javascript program to determine the factorial of a given number.

CODE:
<!DOCTYPE html>

<html>

<body>

<p>factorial calculator</p>

<button onclick="fact()">clickme</button>

<script>

function fact()

let num = prompt("Please enter number");

let i,f=1;

for( i=1;i<=num;i++)

f=f*i;

document.write(num+" factorial is"+f);

</script>

</body>
</html>

OUTPUT:

3.write a Java script to print a table.

CODE:
<!DOCTYPE html>

<html>

<body>

<p>factorial calculator</p>

<script>

let num = prompt("Please enter number");

let i,f=0;

for( i=1;i<=20;i++)

f=num*i;

document.write(num+"*"+i+"="+f);

document.write("</br>");

</script>

</body>

</html>

OUTPUT:
4.write a Java script to implement asimple calculator.

CODE:

<!DOCTYPE html>
<html>
<body>
<p>Array Sum</p>

<script>
let n = parseInt(prompt("Enter size of array"));
let a = new Array(n);
for(let i = 0; i < n; i++) {
a[i] = parseFloat(prompt("Enter array element " + (i + 1)));

}
document.write("array elements");
document.write("<br>");
for(let i = 0; i < n; i++) {
document.write(+a[i]);

document.write("<br>");
}
let sum = 0;
for(let i = 0; i < n; i++) {
sum=sum+a[i];

}
document.write("Sum of array elements: " + sum);
</script>
</body>
</html>

OUTPUT:

5.write a Java script to print the sum of array elements.

CODE:
<!DOCTYPE html>

<html>

<body>

<p>Array Sum</p>

<script>

n = parseInt(prompt("Enter size of array"));

a = new Array(n);

for(let i = 0; i < n; i++) {

a[i] = parseFloat(prompt("Enter array element " + (i + 1)));

let sum = 0;

for(let i = 0; i < n; i++) {

sum=sum+a[i];

document.write("Sum of array elements: " + sum);

</script>

</body>

</html>

OUTPUT:
Taken numbers are:2,3

6. write an HTML page that contains a selection box with a list of 5 countries when the user selects a country, its
capital be printed next in the list, and add CSS to customize the font of the capital (color) bold and font us

CODE:
<!DOCTYPE html>

<html lang="en">

<head>

<title>Select Country and Capital</title>

<style>

body {

font-family: Arial, sans-serif;

margin: 0;

display: flex;

justify-content: center;

align-items: center;

min-height: 100vh;

.container {

width: 400px;

border: 3px solid black;

padding: 20px;

border-radius: 5px;

background-color: #f5f5f5;

}
h3 {

text-align: center;

margin-bottom: 10px;

select {

border: 1px solid #ccc;

padding: 5px;

width: 100%;

#capital-input {

border: 1px solid #ccc;

padding: 5px;

width: 100%;

background-color: #eee;

margin-top: 10px

input[type="text"]::-webkit-input-placeholder {

color: #999;

</style>

</head>

<body>

<div class="container">

<h3>Select Your Country and Capital</h3>

<select id="country-select">

<option value="">Select a Country</option>

<option value="india">India</option>

<option value="germany">Germany</option>

<option value="italy">Italy</option>

<option value="russia">Russia</option>

<option value="uk">United Kingdom</option>


</select>

<br>

<input type="text" id="capital-input" disabled placeholder="Capital City">

</div>

<script>

const countrySelect = document.getElementById("country-select");

const capitalInput = document.getElementById("capital-input");

countrySelect.addEventListener("change", function() {

const selectedCountry = this.value;

let capital;

switch (selectedCountry) {

case "india":

capital = "Delhi";

break;

case "germany":

capital = "Berlin";

break;

case "italy":

capital = "Rome";

break;

case "russia":

capital = "Moscow";

break;

case "uk":

capital = "London";

break;

default:

capital = "";

capitalInput.value = capital;

});

</script>

</body>

</html>
OUTPUT:

7. Write a Java script to validate the following fields of the registration page.

i)First name: The name should contain the alphabet and the length should not be less than 6 characters

ii)password: The password should not be less than 6 characters in length.

iii)Email ID: should contain any invalid and must follow the standard pattern like name@domain.com

iv)Mobile number: The phone number should contain 10 digits only

v)Last name and address should not be empty

vi)gender should not be empty

CODE:
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Registration Form Validation</title>

<script>

function validateRegistration() {

var firstName = document.getElementById('firstName').value.trim();

var lastName = document.getElementById('lastName').value.trim();

var password = document.getElementById('password').value.trim();

var email = document.getElementById('email').value.trim();

var mobileNumber = document.getElementById('mobileNumber').value.trim();

var address = document.getElementById('address').value.trim();

var gender = document.querySelector('input[name="gender"]:checked');

var isValid = true;

var errors = [];


if (firstName.length < 6 || !/^[a-zA-Z]+$/.test(firstName)) {

isValid = false;

errors.push("First name should contain only alphabets and be at least 6 characters long.");

if (lastName === '') {

isValid = false;

errors.push("Last name should not be empty.");

if (password.length < 6) {

isValid = false;

errors.push("Password should be at least 6 characters long.");

if (!/\S+@\S+\.\S+/.test(email)) {

isValid = false;

errors.push("Invalid email address format.");

if (!/^\d{10}$/.test(mobileNumber)) {

isValid = false;

errors.push("Mobile number should contain exactly 10 digits.");

if (address === '') {

isValid = false;

errors.push("Address should not be empty.");

if (!gender) {

isValid = false;

errors.push("Please select a gender.");

if (!isValid) {

var errorMessage = errors.join("\n");

alert(errorMessage);

return isValid;
}

</script>

</head>

<body>

<h2>Registration Form</h2>

<form id="registrationForm" onsubmit="return validateRegistration()">

<label for="firstName">First Name:</label>

<input type="text" id="firstName" name="firstName" required><br><br>

<label for="lastName">Last Name:</label>

<input type="text" id="lastName" name="lastName" required><br><br>

<label for="password">Password:</label>

<input type="password" id="password" name="password" required><br><br>

<label for="email">Email:</label>

<input type="email" id="email" name="email" required><br><br>

<label for="mobileNumber">Mobile Number:</label>

<input type="text" id="mobileNumber" name="mobileNumber" required><br><br>

<label for="address">Address:</label>

<textarea id="address" name="address" rows="4" cols="30" required></textarea><br><br>

<label>Gender:</label>

<input type="radio" id="male" name="gender" value="male" required>

<label for="male">Male</label>

<input type="radio" id="female" name="gender" value="female" required>

<label for="female">Female</label><br><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

OUTPUT:

You might also like