Full Stack Development-1
Full Stack Development-1
LAB MANUAL
FULL STACK DEVELOPMENT – 1
A.Y: 2024-25
Year/Semeter: II/II
Prepared by
K.Raju.
COLLEGE MISSION
DEPARTMENT VISION
5. CSS with Color, Background, Font, Text and CSS Box Model
a. Write a program to demonstrate the various ways you can reference a color in CSS.
b. Write a CSS rule that places a background image halfway down the page, tilting it
horizontally. The image should remain in place when the user scrolls up or down.
c. Write a program using the following terms related to CSS font and text:
i. font-size ii. font-weight iii. font-style
iv. text-decoration v. text-transformation vi. text-alignment
d. Write a program, to explain the importance of CSS Box model using
i. Content ii. Border iii. Margin iv. Padding
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Lists Example</title>
</head>
<body>
<h1>HTML Lists</h1>
<h2>1. Ordered List (Numbered)</h2>
<p>An ordered list is a list where the items are numbered sequentially.</p>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
<h2>2. Unordered List (Bulleted)</h2>
<p>An unordered list is a list where the items are marked with bullet points.</p>
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ul>
<h2>3. Nested Lists</h2>
<p>A nested list is a list within another list. It can be either ordered or unordered.</p>
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Grapes</li>
</ul>
</li>
<li>Vegetables
<ul>
<li>Carrot</li>
<li>Broccoli</li>
<li>Spinach</li>
</ul>
</li>
</ul>
<dt>CSS</dt>
<dd>Cascading Style Sheets, used to style and layout web pages.</dd>
<dt>JavaScript</dt>
<dd>A programming language used to make web pages interactive.</dd>
</dl>
</body>
</html>
P2) Write a HTML program, to explain the working of hyperlinks using <a>
tag and href, target Attributes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Hyperlinks Example</title>
</head>
<body>
</body>
</html>
3) Create a HTML document that has your image and your friend’s image
with a specific height and width. Also when clicked on the images it should
navigate to their respective profiles.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile Images with Links</title>
</head>
<body>
</body>
</html>
4) Write a HTML program, in such a way that, rather than placing large
images on a page, the preferred technique is to use thumbnails by setting the
height and width parameters to something like to 100*100 pixels. Each
thumbnail image is also a link to a full sized version of the image. Create an
image gallery using this technique.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Gallery</title>
<style>
.thumbnail img {
width: 100px;
height: 100px;
object-fit: cover;
}
</style>
</head>
<body>
<h1>Image Gallery</h1>
<div class="gallery">
<!-- Thumbnail 1 -->
<a href="fullsize-image1.jpg" target="_blank" class="thumbnail">
<img src="thumbnail-image1.jpg" alt="Image 1">
</a>
</body>
</html>
EXERCISE:2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Table Example</title>
</head>
<body>
<h1>Working with Tables in HTML</h1>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td>Data 4</td>
<td>Data 5</td>
<td>Data 6</td>
</tr>
</table>
<td>Data B</td>
</tr>
<tr>
<th colspan="2">Colspan Example</th>
<td>Data C</td>
</tr>
</table>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
</body>
</html>
2) Write a HTML program, to explain the working of tables by preparing a
timetable. (Note: Use <caption> tag to set the caption to the table & also use
cell spacing, cell padding, border, rowspan, colspan etc.).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weekly Timetable</title>
<!-- <style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
table {
width: 80%;
margin: 20px auto;
border: 2px solid #333;
border-collapse: collapse;
}
caption {
font-size: 24px;
font-weight: bold;
margin: 10px;
}
th, td {
border: 1px solid #333;
padding: 10px;
text-align: center;
font-size: 18px;
}
th {
background-color: #f2f2f2;
}
td {
background-color: #fafafa;
}
</style> -->
</head>
<body>
<h1>Student Timetable</h1>
</body>
</html>
3) Write a HTML program, to explain the working of forms by designing
Registration form.
(Note: Include text field, password field, number field, date of birth field,
checkboxes, radio buttons, list boxes using <select>&<option> tags, <text
area> and two buttons ie: submit and reset. Use tables to provide a better
view).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<!-- <style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
table {
width: 60%;
margin: 0 auto;
border-collapse: collapse;
}
td {
padding: 10px;
}
th {
text-align: left;
padding: 10px;
background-color: #f2f2f2;
}
input, select, textarea {
width: 100%;
padding: 8px;
margin: 5px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
textarea {
resize: vertical;
}
.form-container {
width: 80%;
margin: auto;
}
h2 {
color: #333;
}
.buttons {
text-align: center;
margin-top: 20px;
}
</style> -->
</head>
<body>
<h1>Registration Form</h1>
<div class="form-container">
<form action="#" method="post">
<table border="1" cellpadding="10">
<!-- Name -->
<tr>
<th>Name:</th>
<td><input type="text" name="name" placeholder="Enter your full name"
required></td>
</tr>
4.1)
Write a HTML program, to explain the working of frames, such that page is
to be divided into 3 parts on either direction. (Note: first frame image,
second frame paragraph, third frame hyperlink. And also make sure of
using “no frame” attribute such that frames to be fixed).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frames Layout</title>
</head>
<body>
<!-- Define the frameset for 3 columns (left image, middle paragraph, right hyperlink) -->
<frameset cols="30%, 40%, 30%" border="5">
<!-- First Frame: Image -->
<frame src="image.html" name="image_frame">
<!-- Fallback content for browsers that do not support frames -->
<noframes>
<body>
<h1>This website uses frames, but your browser does not support frames.</h1>
<p>Please upgrade your browser or view this page in a browser that supports
frames.</p>
</body>
</noframes>
</body>
</html>
4.2)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frames Example</title>
</head>
<body>
<noframes>
<body>
<h2>Your browser does not support frames.</h2>
<p>Please upgrade your browser to view this content.</p>
</body>
</noframes>
</body>
</html>
EXERCISE:3
1) Write a HTML program, that makes use of <article>, <aside>, <figure>,
<figcaption>,<footer>, <header>, <main>, <nav>, <section>, <div>,
<span> tags.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML5 Semantic Tags Example</title>
<!-- <style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
header, footer {
background-color: #333;
color: white;
padding: 10px 0;
text-align: center;
}
nav {
background-color: #444;
padding: 10px;
margin: 10px 0;
text-align: center;
}
nav a {
color: white;
margin: 0 15px;
text-decoration: none;
}
main {
display: flex;
justify-content: space-between;
padding: 20px;
}
section, article {
background-color: white;
padding: 20px;
margin: 10px;
width: 48%;
}
aside {
background-color: #e4e4e4;
padding: 15px;
width: 30%;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
}
figure {
text-align: center;
margin: 20px 0;
}
figcaption {
font-style: italic;
margin-top: 10px;
.container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.box {
background-color: lightblue;
padding: 15px;
margin: 10px;
width: 48%;
}
.highlight {
background-color: yellow;
}
</style> -->
</head>
<body>
<header>
<h1>Welcome to Our Website</h1>
<p>Your go-to place for learning web development</p>
</header>
<nav>
<a href="#home">Home</a>
<a href="#about">About Us</a>
<a href="#services">Services</a>
<a href="#contact">Contact</a>
</nav>
<main>
<section>
<h2>Introduction to Web Development</h2>
<p>Web development involves the creation of websites and web applications. It
encompasses everything from building a simple static page to developing complex web
applications.</p>
</section>
<article>
<h2>Article: Understanding HTML5 Tags</h2>
<p>HTML5 introduced many new semantic tags, such as <code><article></code>,
<code><section></code>, and <code><nav></code>, which help organize content
and improve accessibility.</p>
</article>
<aside>
<h3>Related Resources</h3>
<p>Check out these links to learn more about web development:</p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML">MDN HTML
Documentation</a></li>
<li><a href="https://www.w3schools.com/">W3Schools</a></li>
<li><a href="https://www.freecodecamp.org/">FreeCodeCamp</a></li>
</ul>
</aside>
</main>
<div class="container">
<div class="box">
<h3>Box 1</h3>
<p>This is a div element used for grouping content. It’s a generic container without
semantic meaning.</p>
</div>
<footer>
<p>© 2024 WebDev Academy. All Rights Reserved.</p>
</footer>
</body>
</html>
2) Write a HTML program, to embed audio and video into HTML web
page.
3)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Embedding Audio and Video</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 30px;
}
.media-container {
margin-top: 20px;
}
video, audio {
width: 80%;
max-width: 600px;
margin: 20px 0;
}
</style>
</head>
<body>
<div class="media-container">
<h2>Embedded Audio Example</h2>
<!-- Audio element -->
<audio controls>
<source src="audio_sample.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
</div>
<div class="media-container">
<h2>Embedded Video Example</h2>
<!-- Video element -->
<video controls>
<source src="video_sample.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
</div>
</body>
</html>
4) Write a program to apply different types (or levels of styles or style
specification formats) - inline, internal, external styles to HTML
elements. (identify selector, property and value).
Inside an HTML
Where Inside the <style> tag in In an external .css file, linked
element using the style
Defined the <head> section. via <link> tag.
attribute.
Quick styles for Styles specific to a single Styles shared across multiple
Use Case
individual elements. page. pages or a whole website.
Medium specificity
Highest specificity Low specificity (can be
(applies to matching
Specificity (applies directly to an overridden by inline or internal
elements in the
element). styles).
document).
@import url('styles.css'); or
<p style="color: <style> p {color: blue;}
Example <link rel="stylesheet"
red;">This is red</p> </style>
href="styles.css">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Style Types</title>
<style>
h1 {
color: blue;
font-family: Arial, sans-serif;
}
p{
font-size: 16px;
line-height: 1.6;
}
.external-example {
background-color: #f0f0f0;
padding: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
</body>
</html>
EXERCISE-4
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Selector Types</title>
<style>
/* Simple Selectors */
/* 1. Element Selector */
p{
color: blue; /* Selects all <p> elements */
}
/* 2. ID Selector */
#special {
font-weight: bold; /* Selects the element with ID "special" */
}
/* 3. Class Selector */
.highlight {
background-color: yellow; /* Selects all elements with the class "highlight" */
}
/* 4. Group Selector */
h1, h2, h3 {
font-family: 'Arial', sans-serif; /* Applies to <h1>, <h2>, and <h3> elements */
}
/* 5. Universal Selector */
*{
margin: 0; /* Selects all elements in the page */
}
/* Combinator Selectors */
/* 1. Descendant Selector */
div p {
color: green; /* Selects all <p> elements inside <div> */
}
/* 2. Child Selector */
div > p {
color: red; /* Selects all <p> elements that are direct children of <div> */
}
/* Pseudo-Class Selectors */
/* 2. :nth-child() */
li:nth-child(odd) {
background-color: #f0f0f0; /* Applies to all odd <li> elements */
}
/* 3. :first-child */
div p:first-child {
font-size: 20px; /* Selects the first <p> inside a <div> */
}
/* 4. :last-child */
div p:last-child {
font-weight: bold; /* Selects the last <p> inside a <div> */
}
/* Pseudo-Element Selectors */
/* 1. ::before */
h1::before {
content: "→ "; /* Adds an arrow before every <h1> element */
color: blue;
}
/* 2. ::after */
p::after {
content: " [Read more]"; /* Adds text after every <p> element */
color: green;
}
/* Attribute Selectors */
/* 1. [attribute] */
a[target] {
color: purple; /* Selects all <a> tags that have a "target" attribute */
}
/* 2. [attribute=value] */
input[type="text"] {
border: 2px solid #000; /* Selects all <input> elements where type is "text" */
}
/* 3. [attribute^=value] */
a[href^="https://"] {
color: green; /* Selects all <a> tags whose href attribute starts with "https://" */
}
/* 4. [attribute$=value] */
img[src$=".jpg"] {
border: 3px solid black; /* Selects all <img> elements whose src attribute ends with
".jpg" */
}
/* 5. [attribute*=value] */
a[href*="example"] {
color: orange; /* Selects all <a> tags whose href contains the word "example" */
}
</style>
</head>
<body>
<div>
<p>This <code>p</code> is inside a <code>div</code>, so it is <strong>green</strong>
due to the descendant selector.</p>
<p>This <code>p</code> is a direct child of a <code>div</code>, so it is
<strong>red</strong> due to the child selector.</p>
</div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<div>
<p>This is the first paragraph in a <div>, which has <strong>increased font size</strong>
due to the first-child pseudo-class.</p>
<p>This is the last paragraph in a <div>, which is <strong>bold</strong> due to the last-
child pseudo-class.</p>
</div>
<h1>Section Heading</h1>
<p>This paragraph has an arrow before it because of the ::before pseudo-element.</p>
<p>This paragraph will have "[Read more]" added after it because of the ::after pseudo-
element.</p>
<input type="text" placeholder="Enter text here"> <!-- This input has a border because of the
attribute selector -->
<img src="image.jpg" alt="Image"> <!-- This image will have a border because its src ends
with ".jpg" -->
<a href="https://example.com">Link to example.com</a>
</body>
</html>
EXERCISE-5
1) Write a program to demonstrate the various ways you can reference a color in CSS.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Color References</title>
<style>
/* Using color names */
.color-name {
background-color: skyblue;
color: white;
padding: 10px;
text-align: center;
margin: 5px;
}
<div class="color-name">
Color Name: Skyblue
</div>
<div class="hex-color">
Hexadecimal: #ff6347 (Tomato)
</div>
<div class="rgb-color">
RGB: rgb(255, 99, 71) (Tomato)
</div>
<div class="rgba-color">
RGBA: rgba(255, 99, 71, 0.5) (Tomato with 50% transparency)
</div>
<div class="hsl-color">
HSL: hsl(9, 100%, 64%) (Tomato)
</div>
<div class="hsla-color">
HSLA: hsla(9, 100%, 64%, 0.5) (Tomato with 50% transparency)
</div>
<div class="rgb-percent-color">
RGB with Percent: rgb(100%, 50%, 0%) (Orange-ish)
</div>
<div class="transparent-color">
Transparent Background (No color)
</div>
</body>
</html>
2) Write a CSS rule that places a background image halfway down the
page, tilting it horizontally. The image should remain in place when the
user scrolls up or down.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fixed Background Image with Tilt</title>
<style>
body {
background-image: url('./img2.jpg');
background-position: center 50%; /* Horizontally centered and vertically halfway */
background-attachment: fixed; /* Keeps the background fixed when scrolling */
background-size: cover; /* Ensures the image covers the entire page */
transform: rotate(45deg); /* Tilts the background image by 45 degrees */
height: 100vh; /* Makes sure the body takes full viewport height */
margin: 0; /* Removes default margin */
}
</style>
</head>
<body>
<h1>Fixed and Tilted Background Image</h1>
<p>This background stays in place when scrolling, and is tilted at an angle.</p>
</body>
</html>
3) Write a program using the following terms related to CSS font and text:
i. font-size ii. font-weight iii. font-style
iv. text-decoration v. text-transformation vi. text-alignment
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Font and Text Properties</title>
<style>
/* Set up a container for better control */
.text-container {
width: 80%;
margin: 20px auto;
padding: 20px;
border: 2px solid #ccc;
text-align: center; /* Default text alignment */
}
/* 1. Font Size */
.font-size {
font-size: 32px; /* Larger text size */
margin-bottom: 20px;
}
/* 2. Font Weight */
.font-weight {
font-weight: bold; /* Makes text bold */
margin-bottom: 20px;
}
/* 3. Font Style */
.font-style {
font-style: italic; /* Italic text */
margin-bottom: 20px;
}
/* 4. Text Decoration */
.text-decoration {
text-decoration: underline; /* Underlined text */
margin-bottom: 20px;
}
/* 5. Text Transformation */
.text-transform {
text-transform: uppercase; /* Converts text to uppercase */
margin-bottom: 20px;
}
/* 6. Text Alignment */
.text-align-left {
.text-align-right {
text-align: right; /* Aligns text to the right */
margin-bottom: 20px;
}
.text-align-center {
text-align: center; /* Centers the text */
margin-bottom: 20px;
}
.text-align-justify {
text-align: justify; /* Justifies the text */
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="text-container">
<div class="font-size">
<p>This text demonstrates <strong>font-size</strong>. The size of this text is 32px.</p>
</div>
<div class="font-weight">
<p>This text demonstrates <strong>font-weight</strong>. The text is bold.</p>
</div>
<div class="font-style">
<p>This text demonstrates <strong>font-style</strong>. The text is italicized.</p>
</div>
<div class="text-decoration">
<p>This text demonstrates <strong>text-decoration</strong>. The text is underlined.</p>
</div>
<div class="text-transform">
<p>This text demonstrates <strong>text-transform</strong>. The text is in
uppercase.</p>
</div>
<div class="text-align-left">
<p>This text demonstrates <strong>text-align: left</strong>. The text is aligned to the
left.</p>
</div>
<div class="text-align-right">
<p>This text demonstrates <strong>text-align: right</strong>. The text is aligned to the
right.</p>
</div>
<div class="text-align-center">
<p>This text demonstrates <strong>text-align: center</strong>. The text is centered.</p>
</div>
<div class="text-align-justify">
<p>This text demonstrates <strong>text-align: justify</strong>. The text is justified
(evenly spaced).</p>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Box Model</title>
<style>
/* Styling the container box to illustrate the box model */
.box {
width: 300px; /* Content width */
padding: 20px; /* Padding around the content */
border: 5px solid blue; /* Border around the padding */
margin: 30px; /* Space between the box and other elements */
background-color: lightgray; /* Background color for the content area */
}
.box2 {
width: 200px;
padding: 10px;
border: 3px dashed red;
margin: 15px;
background-color: lightyellow;
}
.box3 {
width: 400px;
padding: 40px;
border: 10px double green;
margin: 50px;
background-color: lightpink;
}
</body> </html>
EXERCISE-6
1) Write a program to embed internal and external JavaScript in a web page.
HTML FILE:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Example: Internal & External</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>JavaScript Example: Internal and External</h1>
<p>This example demonstrates both internal and external JavaScript.</p>
<br><br>
<!-- Button to trigger external JavaScript -->
<button onclick="changeColor()">Click me (External JS)</button>
<!-- External JavaScript File -->
<script src="one.js"></script>
</body>
</html>
function changeColor() {
document.body.style.backgroundColor = "#f0f8ff";
alert("Background color changed to light blue!");
}
2) Write a program to explain the different ways for displaying output.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Different Ways to Display Output</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
#outputDiv {
margin-top: 20px;
padding: 20px;
border: 2px dashed #4CAF50;
}
</style>
</head>
<body>
</body>
</html>
3) Write a program to explain the different ways for taking input.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Different Ways to Take Input in JavaScript</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
#output {
margin-top: 20px;
padding: 20px;
border: 2px dashed #4CAF50;
font-size: 18px;
}
</style>
</head>
<body>
<br><br>
<br><br>
<br><br>
<script>
// 1. Using prompt() to take input from the user
function promptInput() {
var userInput = prompt("Please enter your favorite color:");
if (userInput != null) {
document.getElementById("output").innerHTML = "You entered: " + userInput;
} else {
document.getElementById("output").innerHTML = "No input was provided.";
}
}
</body>
</html>
4) Create a webpage which uses prompt dialogue box to ask a voter for his
name and age. Display the information in table format along with either the
voter can vote or not.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voter Eligibility Check</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
table {
width: 50%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
#output {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div id="output"></div>
<script>
// Function to check voter eligibility
function checkEligibility() {
// Prompt the user for their name and age
var name = prompt("Please enter your name:");
var age = prompt("Please enter your age:");
// Check if the name and age are valid
if (name && age) {
age = parseInt(age); // Convert age to an integer
EXERCISE-7
1) Write a program using document object properties and methods.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Object Methods & Properties</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
#message {
margin-top: 20px;
font-size: 18px;
}
.highlight {
color: red;
}
</style>
</head>
<body>
<h1>Document Object Model (DOM) Methods and Properties</h1>
<div id="message"></div>
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<script>
// 1. Using document.getElementById() to change content
function changeContent() {
var intro = document.getElementById("intro");
intro.innerHTML = "The content has been changed using
<strong>getElementById()</strong>!";
document.getElementById("message").innerHTML = "You successfully changed the
content!";
}
<div id="output"></div>
<script>
// 1. Show an alert box
function showAlert() {
window.alert("This is an alert message!");
}
// 7. Redirect to Google
function redirectToGoogle() {
window.location.href = "https://www.google.com"; // Redirect to Google
}
// 8. Close the current window (if opened via script)
function closeWindow() {
window.close();
}
</script>
</body>
</html>
3) Write a program using array object properties and methods.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array Methods and Properties</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
#output {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div id="output"></div>
<script>
// Array to work with
var fruits = ["Apple", "Banana", "Orange", "Mango", "Grapes"];
// 11. filter() - Creating a new array with elements that meet a condition
var longFruits = fruits.filter(function(fruit) {
return fruit.length > 5; // Get fruits with names longer than 5 characters
});
outputHtml += "<strong>Using filter() to get fruits with names longer than 5
characters:</strong> " + longFruits.join(", ") + "<br>";
// 12. reduce() - Reducing the array to a single value (concatenate all fruit names)
var allFruits = fruits.reduce(function(accumulator, currentValue) {
return accumulator + " " + currentValue; // Concatenate all fruit names into one string
}, "");
outputHtml += "<strong>Using reduce() to concatenate all fruit names:</strong> " +
allFruits + "<br>";
</body>
</html>
4) Write a program using math object properties and methods.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math Object Methods and Properties</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
#output {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<h1>Math Object Methods and Properties</h1>
<div id="output"></div>
<script>
function demonstrateMathMethods() {
var outputHtml = "";
// 1. Math.PI - Value of Pi
outputHtml += "<strong>Math.PI:</strong> " + Math.PI + "<br>";
</body>
</html>
5) Write a program using string object properties and methods.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Object Methods and Properties</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
#output {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div id="output"></div>
<script>
function demonstrateStringMethods() {
var outputHtml = "";
// 13. charCodeAt() - Get the Unicode value of the character at a specified index
outputHtml += "<strong>Unicode value of character at index 7:</strong> " +
str.charCodeAt(7) + "<br>";
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RegExp Object Methods and Properties</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
#output {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div id="output"></div>
<script>
function demonstrateRegExpMethods() {
var outputHtml = "";
// 4. match() - Method of string object to test if the pattern matches the string
var str = "The email address is [email protected].";
var matchResult = str.match(emailPattern);
outputHtml += "<strong>match() - Matching email in string '" + str + "':</strong> " +
(matchResult ? matchResult : "No match found") + "<br>";
// 6. search() - Search for the first match and return the index of the match
var searchResult = str.search(emailPattern);
outputHtml += "<strong>search() - Searching for email in string:</strong> " +
searchResult + "<br>";
</body>
</html>
<div id="output"></div>
<script>
function demonstrateDateMethods() {
var outputHtml = "";
// 4. getDay() - Get the current day of the week (0-6, where 0 is Sunday)
var day = currentDate.getDay();
outputHtml += "<strong>Current Day of the Week (0-6):</strong> " + day + "<br>";
outputHtml += "<strong>Current Day Name:</strong> " + getDayName(day) + "<br>";
// 12. toLocaleDateString() - Get the current date formatted for the locale
outputHtml += "<strong>Current Date (Locale Date):</strong> " +
currentDate.toLocaleDateString() + "<br>";
// 13. toLocaleTimeString() - Get the current time formatted for the locale
outputHtml += "<strong>Current Time (Locale Time):</strong> " +
currentDate.toLocaleTimeString() + "<br>";
</body>
</html>
8) Write a program to explain user-defined object by using properties,
methods, accessors, constructors and display.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User-Defined Object Example: Car</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
#output {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<h1>User-Defined Object Example: Car</h1>
<div id="output"></div>
<script>
// Constructor for Car object
function Car(make, model, year, color) {
this.make = make; // Property
this.model = model; // Property
this.year = year; // Property
this.color = color; // Property
this.currentSpeed = 0; // Property (default speed)
// Method: accelerate
this.accelerate = function() {
this.currentSpeed += 5;
};
// Method: brake
this.brake = function() {
this.currentSpeed -= 5;
if (this.currentSpeed < 0) {
this.currentSpeed = 0; // Prevent negative speed
}
};
// Getter: getCarInfo
this.getCarInfo = function() {
return `${this.year} ${this.make} ${this.model} (${this.color})`;
};
</body>
</html>
EXERCISE:-8
1) Write a program which asks the user to enter three integers, obtains the
numbers from the user and outputs HTML text that displays the larger
number followed by the words “LARGER NUMBER” in an
information message dialog. If the numbers are equal, output HTML
text as “EQUAL NUMBERS”.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Find the Larger Number</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input {
margin: 10px;
padding: 5px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
</style>
</head>
<body>
<script>
function findLargerNumber() {
// Get user input values
var num1 = parseInt(document.getElementById("num1").value);
var num2 = parseInt(document.getElementById("num2").value);
var num3 = parseInt(document.getElementById("num3").value);
// Check if any input is missing
if (isNaN(num1) || isNaN(num2) || isNaN(num3)) {
alert("Please enter valid numbers in all fields.");
return;
}
</body>
</html>
2) Write a program to display week days using switch case.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Display Week Days</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input {
margin: 10px;
padding: 5px;
width: 150px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<script>
function displayDay() {
// Get the number entered by the user
var day = parseInt(document.getElementById("dayNumber").value);
switch(day) {
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
case 7:
dayName = "Sunday";
break;
default:
dayName = "Invalid input! Please enter a number between 1 and 7.";
break;
}
</body>
</html>
3) Write a program to print 1 to 10 numbers using for, while and do-while
loops.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Print Numbers 1 to 10</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
div {
margin-top: 20px;
font-size: 18px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="output"></div>
<script>
function printUsingForLoop() {
let output = "Using For Loop: <br>";
for (let i = 1; i <= 10; i++) {
output += i + " ";
}
document.getElementById("output").innerHTML = output;
}
function printUsingWhileLoop() {
let output = "Using While Loop: <br>";
let i = 1;
while (i <= 10) {
output += i + " ";
i++;
}
document.getElementById("output").innerHTML = output;
}
function printUsingDoWhileLoop() {
let output = "Using Do-While Loop: <br>";
let i = 1;
do {
output += i + " ";
i++;
} while (i <= 10);
document.getElementById("output").innerHTML = output;
}
</script>
</body>
</html>
4) Write aprogram to print data in object using for-in, for-each and for-of
loops.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Object Looping Examples</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
div {
margin-top: 20px;
font-size: 18px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Print Data from an Object Using Different Loops</h1>
<div id="output"></div>
<script>
// Define an object with some data
const person = {
name: "John Doe",
age: 30,
job: "Software Developer",
country: "USA"
};
</body>
</html>
5)Develop a program to determine whether a given number is an
‘ARMSTRONGNUMBER’ or not. [Eg: 153 is an Armstrong number, since
sum of the cube of the digits is equal to the number i.e.,13 + 53+ 33 = 153]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Armstrong Number Check</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input {
margin: 10px;
padding: 5px;
width: 150px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
div {
margin-top: 20px;
font-size: 18px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<button onclick="checkArmstrongNumber()">Check</button>
<div id="result"></div>
<script>
function checkArmstrongNumber() {
// Get the number from the input field
let num = parseInt(document.getElementById("num").value);
// Validate the input
if (isNaN(num)) {
document.getElementById("result").innerHTML = "Please enter a valid number!";
return;
}
// Store the original number to compare later
let originalNum = num;
let sum = 0;
let numOfDigits = num.toString().length; // Get the number of digits
// Check if the sum of the powered digits equals the original number
if (sum === originalNum) {
document.getElementById("result").innerHTML = originalNum + " is an Armstrong
number.";
} else {
document.getElementById("result").innerHTML = originalNum + " is not an
Armstrong number.";
}
}
</script>
</body>
</html>
5)Write a program to display the denomination of the amount deposited in the
bank in terms of 100’s, 50’s, 20’s, 10’s, 5’s, 2’s & 1’s. (Eg: If deposited amount
is Rs.163, the output should be 1-100’s, 1-50’s, 1- 10’s, 1-2’s & 1-1’s).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Denomination of Amount</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input {
padding: 5px;
margin-top: 10px;
width: 150px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
div {
margin-top: 20px;
font-size: 18px;
margin-bottom: 10px;
word-wrap: break-word;
}
</style>
</head>
<body>
<div id="result"></div>
<script>
function calculateDenominations() {
// Get the deposited amount from input
let amount = parseInt(document.getElementById("amount").value);
// Check if the amount is a valid number
if (isNaN(amount) || amount <= 0) {
document.getElementById("result").innerHTML = "Please enter a valid amount
greater than 0.";
return;
}
// Denominations available
let denominations = [100, 50, 20, 10, 5, 2, 1];
let result = "Denominations for Rs." + amount + " are:<br>";
document.getElementById("result").innerHTML = result;
}
</script>
</body>
</html>
EXERCISE:-9
1) Design a appropriate function should be called to display
i. Factorial of that number
ii. Fibonacci series up to that number
iii. Prime numbers up to that number
iv. Is it palindrome or not
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Operations</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input {
padding: 5px;
margin-top: 10px;
width: 150px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
div {
margin-top: 20px;
font-size: 18px;
margin-bottom: 10px;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Number Operations</h1>
<div id="result"></div>
<script>
// Function to calculate the factorial of a number
function factorial(num) {
let result = 1;
for (let i = 1; i <= num; i++) {
result *= i;
}
return result;
}
</body>
</html>
2) Design a HTML having a text box and four buttons named Factorial,
Fibonacci, Prime,and Palindrome. When a button is pressed an appropriate
function should be called todisplay
i. Factorial of that number
ii. Fibonacci series up to that number
iii. Prime numbers up to that number
iv. Is it palindrome or not
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Operations</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input {
padding: 5px;
margin-top: 10px;
width: 150px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 10px;
}
div {
margin-top: 20px;
font-size: 18px;
margin-bottom: 10px;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Number Operations</h1>
<button onclick="calculateFactorial()">Factorial</button>
<button onclick="generateFibonacci()">Fibonacci</button>
<button onclick="findPrimeNumbers()">Prime Numbers</button>
<button onclick="checkPalindrome()">Palindrome</button>
<div id="result"></div>
<script>
// Function to calculate the factorial of a number
function calculateFactorial() {
let num = parseInt(document.getElementById("number").value);
if (isNaN(num) || num <= 0) {
document.getElementById("result").innerHTML = "Please enter a valid positive
number.";
return;
}
let result = 1;
for (let i = 1; i <= num; i++) {
result *= i;
}
document.getElementById("result").innerHTML = `Factorial of ${num} is: ${result}`;
}
</body>
</html>
3)Write a program to validate the following fields in a registration page
i.Name (start with alphabet and followed by alphanumeric and the length
should
not be less than 6 characters)
ii. Mobile (only numbers and length 10 digits)
iii. E-mail (should contain format like [email protected])
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin-top: 50px;
text-align: center;
}
form {
width: 300px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.error {
color: red;
font-size: 14px;
}
</style>
</head>
<body>
<h1>Registration Form</h1>
<form id="registrationForm" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name">
<span class="error" id="nameError"></span>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email">
<span class="error" id="emailError"></span>
<button type="submit">Register</button>
</form>
<script>
function validateForm() {
let valid = true;