Av SC U4aie23153
Av SC U4aie23153
Av SC U4aie23153
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>
<script>
function checkEligibility() {
age = parseInt(age);
if (isNaN(age)) {
} else {
} else {
</script>
</head>
<body>
</body>
</html>
OUTPUT:
CODE:
<!DOCTYPE html>
<html>
<body>
<p>factorial calculator</p>
<button onclick="fact()">clickme</button>
<script>
function fact()
let i,f=1;
for( i=1;i<=num;i++)
f=f*i;
</script>
</body>
</html>
OUTPUT:
CODE:
<!DOCTYPE html>
<html>
<body>
<p>factorial calculator</p>
<script>
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:
CODE:
<!DOCTYPE html>
<html>
<body>
<p>Array Sum</p>
<script>
a = new Array(n);
let sum = 0;
sum=sum+a[i];
</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>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
.container {
width: 400px;
padding: 20px;
border-radius: 5px;
background-color: #f5f5f5;
}
h3 {
text-align: center;
margin-bottom: 10px;
select {
padding: 5px;
width: 100%;
#capital-input {
padding: 5px;
width: 100%;
background-color: #eee;
margin-top: 10px
input[type="text"]::-webkit-input-placeholder {
color: #999;
</style>
</head>
<body>
<div class="container">
<select id="country-select">
<option value="india">India</option>
<option value="germany">Germany</option>
<option value="italy">Italy</option>
<option value="russia">Russia</option>
<br>
</div>
<script>
countrySelect.addEventListener("change", function() {
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
iii)Email ID: should contain any invalid and must follow the standard pattern like name@domain.com
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function validateRegistration() {
isValid = false;
errors.push("First name should contain only alphabets and be at least 6 characters long.");
isValid = false;
if (password.length < 6) {
isValid = false;
if (!/\S+@\S+\.\S+/.test(email)) {
isValid = false;
if (!/^\d{10}$/.test(mobileNumber)) {
isValid = false;
isValid = false;
if (!gender) {
isValid = false;
if (!isValid) {
alert(errorMessage);
return isValid;
}
</script>
</head>
<body>
<h2>Registration Form</h2>
<label for="password">Password:</label>
<label for="email">Email:</label>
<label for="address">Address:</label>
<label>Gender:</label>
<label for="male">Male</label>
<label for="female">Female</label><br><br>
</form>
</body>
</html>
OUTPUT: