Web Practicals 1
Web Practicals 1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heading Tags & Text Formatting</title>
</head>
<body>
<h1>This is H1 Heading</h1>
<h2>This is H2 Heading</h2>
<h3>This is H3 Heading</h3>
<h4>This is H4 Heading</h4>
<h5>This is H5 Heading</h5>
<h6>This is H6 Heading</h6>
</body>
</html>
Design a web page using different HTML tags like
c) Alignment
SOLUTION:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Web Page</title>
</head>
<body bgcolor="lightgray">
<p>
<b>This is a bold text.</b>
</p>
<p>
<i>This is italic text.</i>
</p>
<p>
<u>This is underlined text.</u>
</p>
<p>
<b><i><u>This is bold, italic, and underlined text.</u></i></b>
</p>
<hr>
<p align="left">
This paragraph is left-aligned.
</p>
<p align="center">
This paragraph is center-aligned.
</p>
<p align="right">
This paragraph is right-aligned.
</p>
</body>
</html>
Design a web page with links to different pages and allow navigation between them.
SOLUTION:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page</title>
</head>
<body bgcolor="lightgray">
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Us</title>
</head>
<body bgcolor="lightblue">
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact</title>
</head>
<body bgcolor="lightyellow">
</body>
</html>
Design a web page that demonstrates all style sheet types.
SOLUTION:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Types Demo</title>
</body>
</html>
.external {
color: purple;
font-size: 22px;
font-weight: bold;
}
Design a web page with ordered and unordered lists.
SOLUTION:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lists in HTML</title>
</head>
<body bgcolor="lightgray">
</body>
</html>
Design a web page using different table properties like padding, cell padding, and merging.
<!DOCTYPE html>
<html>
<head>
<title>Table Layout</title>
</head>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: orange; /* Full Background Color */
margin: 0;
padding: 0;
display: flex;
align-items: center;
height: 100vh;
}
.container {
width: 350px;
<div>
<h2>Student Registration Form</h2>
<p>Fill in this form to register</p>
<form>
<label>First Name</label>
<input type="text" placeholder="Enter your first name">
<label>Last Name</label>
<input type="text" placeholder="Enter your last name">
<label>E-mail</label>
<input type="email" placeholder="Enter your e-mail">
<label>Date of Birth</label>
<input type="date">
<label>Set Username</label>
<input type="text" placeholder="Set Username">
<label>Set Password</label>
<input type="password" placeholder="Set password">
<label>Gender</label>
<div class="gender">
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female
<input type="radio" name="gender"> Others
</div>
<label>Course</label>
<select>
<option>Course</option>
<option>BSc IT</option>
<option>Engineering</option>
<option>Management</option>
</select>
</body>
</html>
Write a JavaScript Program to design a simple calculator.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<script>
function appendValue(value) {
document.getElementById("display").value += value;
}
function clearDisplay() {
document.getElementById("display").value = "";
}
function calculate() {
try {
document.getElementById("display").value =
eval(document.getElementById("display").value);
} catch (error) {
alert("Invalid Expression");
}
}
</script>
</head>
<body>
<h2>Simple Calculator</h2>
<button onclick="clearDisplay()">C</button>
<button onclick="appendValue('1')">1</button>
<button onclick="appendValue('2')">2</button>
<button onclick="appendValue('+')">+</button>
<br><br>
<button onclick="appendValue('3')">3</button>
<button onclick="appendValue('4')">4</button>
<button onclick="appendValue('5')">5</button>
<button onclick="appendValue('-')">-</button>
<br><br>
<button onclick="appendValue('6')">6</button>
<button onclick="appendValue('7')">7</button>
<button onclick="appendValue('8')">8</button>
<button onclick="appendValue('*')">*</button>
<br><br>
<button onclick="appendValue('9')">9</button>
<button onclick="appendValue('0')">0</button>
<button onclick="calculate()">=</button>
<button onclick="appendValue('/')">/</button>
</body>
</html>
Using JavaScript, design a web page to accept a number from the user and print its Factorial.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Factorial Calculator</title>
</head>
<body>
<h2>Factorial Calculator</h2>
<label>Enter a number:</label>
<input type="number" id="numberInput">
<button onclick="calculateFactorial()">Calculate</button>
<script>
function calculateFactorial() {
let num = document.getElementById("numberInput").value;
let factorial = 1;
if (num < 0) {
document.getElementById("result").innerText = "Factorial not
defined for negative numbers";
return;
}
document.getElementById("result").innerText = factorial;
}
</script>
</body>
</html>
Write a program in JavaScript to accept a sentence from the user and display the number of words in
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word Counter</title>
</head>
<body>
<h2>Word Counter</h2>
<label>Enter a sentence:</label>
<input type="text" id="sentenceInput">
<button onclick="countWords()">Count Words</button>
<script>
function countWords() {
let sentence = document.getElementById("sentenceInput").value;
let count = 0;
let inWord = false;
if (char !== ' ' && char !== '\t' && char !== '\n') {
if (!inWord) {
count++;
inWord = true;
}
} else {
inWord = false;
}
}
document.getElementById("result").innerText = count;
}
</script>
</body>
</html>
Write a JavaScript program to display all the prime numbers between 1 and 100.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prime Numbers (1-100)</title>
</head>
<body>
<p id="result"></p>
<script>
function isPrime(num) {
if (num < 2) return false;
for (let i = 2; i <= num / 2; i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
function displayPrimes() {
let primes = "";
for (let i = 1; i <= 100; i++) {
if (isPrime(i)) {
primes += i + " ";
}
}
document.getElementById("result").innerText = primes;
}
</script>
</body>
</html>
Write a JavaScript program that takes three numbers from the user and finds the smallest and
largest number using the Math.min() and Math.max() functions.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Find Smallest and Largest Number</title>
</head>
<body>
<button onclick="findNumbers()">Find</button>
<script>
function findNumbers() {
let n1 = document.getElementById("num1").value;
let n2 = document.getElementById("num2").value;
let n3 = document.getElementById("num3").value;
</body>
</html>
Write a JavaScript program that takes a number as a string input from the user and converts it into a
number using the Number object. Then, display its type before and after conversion.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String to Number Conversion</title>
</head>
<body>
<script>
function convertNumber() {
let input = document.getElementById("numInput").value;
let beforeType = typeof input; // Get type before conversion
</body>
</html>