0% found this document useful (0 votes)
7 views

intpr

Uploaded by

binitghosh326
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

intpr

Uploaded by

binitghosh326
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

<!

-- Question 1: -->

<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<script>
function validateForm() {
const name = document.forms["regForm"]["name"].value;
const email = document.forms["regForm"]["email"].value;
const password = document.forms["regForm"]["password"].value;
const phone = document.forms["regForm"]["phone"].value;
if (!name || !email || !password || !phone) {
alert("All fields are required!");
return false;
}
if ([email protected](email)) {
alert("Invalid email format!");
return false;
}
if (password.length < 6) {
alert("Password must be at least 6 characters long!");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="regForm" onsubmit="return validateForm()">
<label>Name:</label><input type="text" name="name"><br>
<label>Email:</label><input type="email" name="email"><br>
<label>Password:</label><input type="password" name="password"><br>
<label>Phone:</label><input type="tel" name="phone"><br>
<label>Gender:</label>
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select><br>
<button type="submit">Register</button>
</form>
</body>
</html>

<!-- Question 2: -->

<?php
$colors = ["Red", "Blue", "Green", "Yellow", "Pink"];
rsort($colors);
foreach ($colors as $color) {
echo $color . "\n";
}
?>

<!-- Question 3: -->

<!-- ......................adress.xml...........................
-->

<!DOCTYPE address SYSTEM "address.dtd">


<address>
<name>John Doe</name>
<company>XYZ Corp</company>
<phoneNumber>1234567890</phoneNumber>
</address>

<!-- ......................address.dtd...........................
-->

<!ELEMENT address (name, company, phoneNumber)>


<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phoneNumber (#PCDATA)>

<!-- Question 4: -->

<!DOCTYPE address [
<!ELEMENT address (name, company, phoneNumber)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phoneNumber (#PCDATA)>
]>
<address>
<name>Jane Smith</name>
<company>ABC Inc</company>
<phoneNumber>9876543210</phoneNumber>
</address>

<!-- Question 5: -->

<?php
$employees = ["Alice" => 25, "Bob" => 30, "Charlie" => 28, "David" => 35, "Eve" =>
22];
foreach ($employees as $name => $age) {
echo "$name: $age years old \n" ;
}
?>

<!-- Question 6: -->

<!-- ......................form.html...........................
-->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
</head>
<body>
<form action="process.php" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>

<button type="submit">Submit</button>
</form>
</body>
</html>

<!-- ......................process.php...........................
-->

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve the username and password from the POST request
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);

echo "<h2>Form Submitted</h2>";


echo "Username: " . $username . "<br>";
echo "Password: " . $password . "<br>";
}
?>
<!-- Question 7: -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Marks Table</title>
</head>
<body>
<h2>Student Marks</h2>
<table border="1" cellspacing="5" cellpadding="5">
<tr>
<th rowspan="2">Name</th>
<th colspan="2">Marks</th>
</tr>
<tr>
<th>Math</th>
<th>Science</th>
</tr>
<tr>
<td>John</td>
<td>85</td>
<td>90</td>
</tr>
<tr>
<td>Emma</td>
<td>78</td>
<td>88</td>
</tr>
<tr>
<td>Michael</td>
<td>92</td>
<td>84</td>
</tr>
<tr>
<td>Sophia</td>
<td>89</td>
<td>91</td>
</tr>
<tr>
<td>David</td>
<td>76</td>
<td>79</td>
</tr>
</table>
</body>
</html>

<!-- Question 8: -->


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<style>
button{
width:1.5rem;
margin:1px;
}
</style>
</head>
<body>
<h1>Calculator</h1>
<input type="text" id="result"><br><br>
<button onclick="appendValue('7')">7</button>
<button onclick="appendValue('8')">8</button>
<button onclick="appendValue('9')">9</button>
<button onclick="appendValue('/')">/</button><br>
<button onclick="appendValue('4')">4</button>
<button onclick="appendValue('5')">5</button>
<button onclick="appendValue('6')">6</button>
<button onclick="appendValue('*')">*</button><br>
<button onclick="appendValue('1')">1</button>
<button onclick="appendValue('2')">2</button>
<button onclick="appendValue('3')">3</button>
<button onclick="appendValue('-')">-</button><br>
<button onclick="appendValue('0')">0</button>
<button onclick="calculateResult()" style="width:3.38rem;">=</button>
<button onclick="appendValue('+')">+</button>

<script>
function appendValue(value) {
document.getElementById('result').value += value;
}
function calculateResult() {
try {
document.getElementById('result').value =
eval(document.getElementById('result').value);
} catch {
document.getElementById('result').value = 'Error';
}
}
</script>
</body>
</html>

<!-- Question 9: -->


<!DOCTYPE html>
<html>
<head>
<style>
.internal { color: blue; }
</style>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p style="color: red;">Inline Style</p>
<p class="internal">Internal Style</p>
<p class="external">External Style</p>
</body>
</html>

/* styles.css */

.external { font-weight: bold; }

<!-- Question 10: -->

<!DOCTYPE html>
<html>
<head>
<script>
function factorial(num) {
let result = 1;
for (let i = 1; i <= num; i++) result *= i;
return result;
}
</script>
</head>
<body>
<button onclick="alert('Factorial: ' + factorial(5))">Inline JS</button>
<script>
function checkEvenOdd(num) {
alert(num % 2 === 0 ? "Even" : "Odd");
}
</script>
<button onclick="checkEvenOdd(4)">Internal JS</button>
<script src="script.js"></script>
<button onclick="checkPrime(7)">External JS</button>
</body>
</html>

/* script.js */
function checkPrime(num) {
if (num < 2) return alert("Not Prime");
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) return alert("Not Prime");
}
alert("Prime");
}

<!-- Question 11: -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Selectors</title>
<style>
/* Global Selector */
* {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}

/* Class Selector */
.highlight {
color: white;
background-color: blue;
padding: 10px;
border-radius: 5px;
}

/* ID Selector */
#main-heading {
color: green;
text-align: center;
margin-top: 20px;
font-size: 24px;
}
</style>
</head>
<body>
<!-- Applying ID Selector -->
<h1 id="main-heading">CSS Selectors Example</h1>

<!-- Applying Class Selector -->


<p class="highlight">This paragraph is styled using a class selector.</p>

<!-- Global Selector in effect -->


<p>This paragraph inherits styles from the global selector.</p>
</body>
</html>
<!-- Question 12: -->

const date = new Date();


const n = date.toDateString();
const time = date.toLocaleTimeString();
console.log('Date: ' + n);
console.log('Time: ' + time);

<!-- Question 13: -->

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Celcius to Fahrenhet</h2>

<p><input id="c" onkeyup="convert('C')"> degrees Celsius</p>

<p><input id="f" onkeyup="convert('F')"> degrees Fahrenheit</p>

<script>
function convert(degree) {
var x;
if (degree == "C") {
x = document.getElementById("c").value * 9 / 5 + 32;
document.getElementById("f").value = Math.round(x);
} else {
x = (document.getElementById("f").value -32) * 5 / 9;
document.getElementById("c").value = Math.round(x);
}
}
</script>

</body>
</html>

<!-- Question 14: -->


function checkLeapYear(year) {

if ((0 == year % 4) && (0 != year % 100) || (0 == year % 400)) {


console.log(year + ' is a leap year');
} else {
console.log(year + ' is not a leap year');
}
}

const year = prompt('Enter a year:');

checkLeapYear(year);

<!-- Question 15: -->

function checkMultiple(number) {
if (number % 3 === 0 && number % 7 === 0) {
console.log(`${number} is a multiple of both 3 and 7.`);
} else if (number % 3 === 0) {
console.log(`${number} is a multiple of 3.`);
} else if (number % 7 === 0) {
console.log(`${number} is a multiple of 7.`);
} else {
console.log(`${number} is not a multiple of 3 or 7.`);
}
}

const number = parseInt(prompt("Enter a number: "), 10);


if (!isNaN(number)) {
checkMultiple(number);
} else {
console.log("Please enter a valid number.");
}

You might also like