FSD FINAL LAB MANUAL
FSD FINAL LAB MANUAL
<section>
<h2>1. Ordered List</h2>
<p>An ordered list uses numbers or letters to order items:</p>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
</section>
<section>
<h2>2. Unordered List</h2>
<p>An unordered list uses bullet points:</p>
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
</section>
<section>
<h2>3. Nested Lists</h2>
<p>You can nest lists inside one another:</p>
<ul>
<li>Outer item 1
<ul>
<li>Nested item 1.1</li>
<li>Nested item 1.2</li>
</ul>
</li>
<li>Outer item 2</li>
</ul>
</section>
<section>
<h2>4. Ordered List in an Unordered List</h2>
<p>You can mix list types by placing an ordered list inside an
unordered list:</p>
<ul>
<li>Item A
<ol>
<li>Sub-item A.1</li>
<li>Sub-item A.2</li>
</ol>
</li>
<li>Item B</li>
</ul>
</section>
<section>
<h2>5. Definition List</h2>
<p>A definition list pairs terms with their descriptions:</p>
<dl>
<dt>HTML</dt>
<dd>HyperTextMarkup Language, used to create webpages.</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets, used to style webpages.</dd>
<dt>JavaScript</dt>
<dd>A programming language used to create interactive effects
within web browsers.</dd>
</dl>
</section>
</body>
</html>
<!DOCTYPE html>
<htmllang="en">
<head>
<title>Hyperlinks in HTML</title>
</head>
<body>
<h1>Working with Hyperlinks in HTML</h1>
<section>
<h2>1. Basic Hyperlink</h2>
<p>This is a basic hyperlink using the <code><a></code> tag and
the <code>href</code> attribute:</p>
<ahref="https://www.google.com">Visit Example Website</a>
</section>
<section>
<h2>2. Open Link in New Tab</h2>
<p>Use the <code>target="_blank"</code> attribute to open the link in
a new tab:</p>
<ahref="https://www.google.com"target="_blank">Open Google in New
Tab</a>
</section>
<section>
<h2>3. Link to an Email Address</h2>
<p>Use <code>mailto:</code> in the <code>href</code> attribute to
create an email link:</p>
<ahref="mailto:someone@example.com">Send an Email</a>
</section>
<section>
<h2>4. Link to a Specific Section in the Same Page</h2>
<p>Create an anchor link to jump to another section of the page:</p>
<ahref="#section5">Go to Section 5</a>
</section>
<section>
<h2>5. Section for Anchor Link</h2>
<pid="section5">This is the section you jumped to using the anchor
link!</p>
</section>
<section>
<h2>6. Downloadable File Link</h2>
<p>Use the <code>download</code> attribute to allow users to download
a file:</p>
<ahref="example-file.txt"download>Download Example File</a>
</section>
</body>
</html>
1.C Create a HTML documentthat has your image andyour friend’s image with a specificheight and width.
Also when clicked on the images it should navigate to their respectiveprofiles.
<!DOCTYPE html>
<htmllang="en">
<head>
</head>
<body>
<h1>Profiles</h1>
<p>Click on the images below to view the respective profiles.</p>
profile1.html
<!DOCTYPE html>
<htmllang="en">
<head>
<title>profile 1</title>
</head>
<body>
<h1>Profiles</h1>
<p>Guido van Rossum is the creator of the Python programming language. He
grew up in the Netherlands and studied at the University of Amsterdam, where
he graduated with a Master's Degree in Mathematics and Computer Science. </p>
</body>
</html>
profile2.html
<!DOCTYPE html>
<htmllang="en">
<head>
<title>profile 1</title>
</head>
<body>
<h1>Profiles 2</h1>
<p>Guido van Rossum is the creator of the Python programming language. He
grew up in the Netherlands and studied at the University of Amsterdam, where
he graduated with a Master's Degree in Mathematics and Computer Science. His
first job after college was as a programmer at CWI, where he worked on the
ABC language, the Amoeba distributed operating system, and a variety of
multimedia projects. During this time he created Python as side project. He
then moved to the United States to take a job at a non-profit research lab in
Virginia, married a Texan, worked for several other startups, and moved to
California. In 2005 he joined Google, where he obtained the rank of Senior
Staff Engineer, and in 2013 he started working for Dropbox as a Principal
Engineer..</p>
</body>
1.D Write a HTMLprogram, in such away that,rather than placing largeimageson a page,the preferred
technique is to use thumbnails by setting the height and width parameters tosomething
liketo100*100pixels.Eachthumbnail imageisalsoalink toa
fullsizedversionoftheimage.Createanimagegalleryusingthistechnique
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Thumbnail Image Gallery</title>
</head>
<body>
<h1>Image Gallery</h1>
<p>Click on a thumbnail to view the full-sized image.</p>
<divclass="gallery">
<!-- Image 1 -->
<ahref="img_forest.jpg"target="_blank">
<imgsrc="img_forest.jpg"alt="Image 1"width="150"height="150">
</a>
<!-- Image 2 -->
<ahref="image_tree.webp"target="_blank">
<imgsrc="image_tree.webp"alt="Image 1"width="150"height="150">
</a>
<!-- Image 3 -->
<ahref="img_forest.jpg"target="_blank">
<imgsrc="img_forest.jpg"alt="Image 1"width="150"height="150">
</a>
<!-- Image 4 -->
<ahref="img_forest.jpg"target="_blank">
<imgsrc="img_forest.jpg"alt="Image 1"width="150"height="150">
</a>
</div>
</body>
</html>
2.A WriteaHTMLprogram,toexplaintheworkingoftables.(usetags:<table>,<tr>,<th>,<td>and
Attributes:border,rowspan,colspan)
<!DOCTYPE html>
<htmllang="en">
<head>
<title>Table Example</title>
</head>
<body>
<h1style="text-align: center;">Table Example</h1>
<tableborder="1">
<!-- Table Header Row -->
<tr>
<throwspan="2">Name</th>
<thcolspan="2">Scores</th>
<throwspan="2">Total</th>
</tr>
<tr>
<th>Math</th>
<th>Science</th>
</tr>
<!-- Table Data Rows -->
<tr>
<td>John</td>
<td>85</td>
<td>90</td>
<td>175</td>
</tr>
<tr>
<td>Jane</td>
<td>92</td>
<td>88</td>
<td>180</td>
</tr>
<tr>
<td>Sam</td>
<td>78</td>
<td>84</td>
<td>162</td>
</tr>
</table>
</body>
</html>
2.B WriteaHTMLprogram,toexplaintheworkingoftablesbypreparingatimetable. (Note: Use <caption> tag to
set the caption to the table & also use cell spacing,cellpadding,border,rowspan,colspan etc.).
<!DOCTYPE html>
<htmllang="en">
<head>
<title>Timetable Example</title>
</head>
<body>
<h1style="text-align: center;">Weekly Timetable</h1>
<tablecellspacing="5"cellpadding="10"border="1">
<caption><strong>Class Timetable</strong></caption>
<tr>
<throwspan="2">Day</th>
<thcolspan="4">Subjects</th>
</tr>
<tr>
<th>9:00 - 10:00</th>
<th>10:00 - 11:00</th>
<th>11:00 - 12:00</th>
<th>12:00 - 1:00</th>
</tr>
<tr>
<td>Monday</td>
<td>Math</td>
<td>English</td>
<td>Science</td>
<td>History</td>
</tr>
<tr>
<td>Tuesday</td>
<td>Geography</td>
<td>Math</td>
<tdrowspan="2">Physical Education</td>
<td>Computer Science</td>
</tr>
<tr>
<td>Wednesday</td>
<td>English</td>
<td>History</td>
<td>Biology</td>
</tr>
<tr>
<td>Thursday</td>
<td>Science</td>
<td>Math</td>
<td>English</td>
<td>Art</td>
</tr>
<tr>
<td>Friday</td>
<td>History</td>
<td>Computer Science</td>
<td>Geography</td>
<td>Math</td>
</tr>
</table>
</body>
</html>
2.C Write a HTML program, to explain the working of forms by designing Registration form.(Note:Includetext
field,passwordfield,number field,dateof birth field,checkboxes,radio buttons, list boxes using
<select>&<option> tags, <text area> and two buttons ie:submit
andreset.Usetablestoprovideabetterview).
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
</head>
<body>
<h2style="text-align: center;">Registration Form</h2>
<formaction="#"method="post">
<tableborder="1">
<tr>
<thcolspan="2">Fill Your Details</th>
</tr>
<tr>
<td>Full Name:</td>
<td><inputtype="text"name="fullname"placeholder="Enter your
full name"required></td>
</tr>
<tr>
<td>Password:</td>
<td><inputtype="password"name="password"placeholder="Enter
your password"required></td>
</tr>
<tr>
<td>Age:</td>
<td><inputtype="number"name="age"min="1"placeholder="Enter
your age"required></td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><inputtype="date"name="dob"required></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<inputtype="radio"name="gender"value="male"id="male"required>
<labelfor="male">Male</label>
<inputtype="radio"name="gender"value="female"id="female"required>
<labelfor="female">Female</label>
</td>
</tr>
<tr>
<td>Languages Known:</td>
<td>
<inputtype="checkbox"name="language"value="english"id="english">
<labelfor="english">English</label>
<inputtype="checkbox"name="language"value="hindi"id="hindi">
<labelfor="hindi">Hindi</label>
<inputtype="checkbox"name="language"value="french"id="french">
<labelfor="french">French</label>
</td>
</tr>
<tr>
<td>Country:</td>
<td>
<selectname="country"required>
<optionvalue="">--Select Your Country--</option>
<optionvalue="usa">USA</option>
<optionvalue="canada">Canada</option>
<optionvalue="india">India</option>
<optionvalue="uk">UK</option>
<optionvalue="australia">Australia</option>
</select>
</td>
</tr>
<tr>
<td>Address:</td>
<td>
<textareaname="address"rows="4"placeholder="Enter your
address"></textarea>
</td>
</tr>
<tr>
<tdclass="buttons"colspan="2">
<inputtype="submit"value="Submit">
<inputtype="reset"value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>
2.D Write a HTML program, to explain the working of frames, such that page is to be dividedinto 3 parts on
either direction. (Note: first frame image, second frame paragraph,third framehyperlink.And
alsomakesure ofusing“noframe” attributesuchthatframestobefixed).
<!DOCTYPE html>
<html>
<head>
<title>Frameset Example</title>
</head>
<framesetcols="33%, 33%, 34%">
<!-- First frame: Displays an image -->
<framesrc="image_frame.html"name="frame1" />
<!DOCTYPE html>
<html>
<head>
<title>Image Frame</title>
</head>
<body>
<h2>Image Frame</h2>
<imgsrc="img_forest.jpg"alt="Sample Image"width="300"height="200">
</body>
</html>
paragraph_frame.html
<!DOCTYPE html>
<html>
<head>
<title>Paragraph Frame</title>
</head>
<body>
<h2>Paragraph Frame</h2>
<p>
This is a demonstration of using frames in HTML. Frames allow you to
divide a browser window into multiple sections, each loading separate HTML
files.
</p>
</body>
</html>
link_frame.html
<!DOCTYPE html>
<html>
<head>
<title>Link Frame</title>
</head>
<body>
<h2>Hyperlink Frame</h2>
<p>
Visit: <ahref="https://www.google.com"target="_blank">Example
Website</a>
</p>
</body>
</html>
3.A WriteaHTMLprogram,thatmakesuseof<article>,<aside>,<figure>,<figcaption>,<footer>,<header>,<main>,<na
v>,<section>,<div>,<span>tags.
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Semantic HTML Example</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
}
header {
background: #333;
color: #fff;
padding: 1rem;
text-align: center;
}
nav {
background: #444;
color: #fff;
padding: 0.5rem;
text-align: center;
}
nav a {
color: #fff;
margin: 0 1rem;
text-decoration: none;
}
main {
display: flex;
flex-wrap: wrap;
padding: 1rem;
}
article {
flex: 2;
padding: 1rem;
background: #f4f4f4;
margin: 1rem;
}
aside {
flex: 1;
padding: 1rem;
background: #ddd;
margin: 1rem;
}
figure {
margin: 1rem 0;
text-align: center;
}
figcaption {
font-style: italic;
}
footer {
background: #333;
color: #fff;
text-align: center;
padding: 1rem;
margin-top: 1rem;
}
</style>
</head>
<body>
<header>
<center> <h1>Welcome to My Website</h1></center>
</header>
<navstyle="flex:1;">
<ahref="#home">Home</a>
<ahref="#about">About</a>
<ahref="#contact">Contact</a>
</nav>
<main>
<article>
<h2>Article Title</h2>
<p>This is the main content area. Here is where the primary
content of the webpage is displayed. You can add more paragraphs, images, and
other elements as needed.</p>
<figure>
<imgsrc="https://via.placeholder.com/400"alt="Placeholder
image">
<figcaption>A placeholder image with a caption.</figcaption>
</figure>
<p>Loremipsumdolor sitamet, consecteturadipiscingelit. Sed do
eiusmodtemporincididuntutlabore et dolore magna aliqua.</p>
</article>
<aside>
<h3>Related Links</h3>
<ul>
<li><ahref="#">Link 1</a></li>
<li><ahref="#">Link 2</a></li>
<li><ahref="#">Link 3</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2024 My Website. All rights reserved.</p>
</footer>
</body>
</html>
3.B WriteaHTMLprogram,toembedaudioandvideointoHTMLwebpage.
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Audio and Video Embedding</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
text-align: center;
padding: 1rem;
}
audio, video {
margin: 1rem 0;
width: 80%;
max-width: 600px;
}
</style>
</head>
<body>
<header>
<h1>Embedding Audio and Video in HTML</h1>
</header>
<main>
<section>
<h2>Audio Example</h2>
<p>Here is an example of an audio file embedded in this
webpage:</p>
<audiocontrols>
<sourcesrc="audio-example.mp3"type="audio/mpeg">
<sourcesrc="audio-example.ogg"type="audio/ogg">
Your browser does not support the audio element.
</audio>
</section>
<section>
<h2>Video Example</h2>
<p>Here is an example of a video file embedded in this
webpage:</p>
<videocontrols>
<sourcesrc="video-example.mp4"type="video/mp4">
<sourcesrc="video-example.ogg"type="video/ogg">
Your browser does not support the video element.
</video>
</section>
</main>
<footer>
<p>© 2024 My Webpage. All rights reserved.</p>
</footer>
</body>
</html>
3.C Write a program to apply different types (or levels of styles or stylespecificationformats)-
inline,internal,externalstylestoHTMLelements.(identifyselector,propertyandvalue).
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>CSS Styling Example</title>
<!-- External CSS -->
<linkrel="stylesheet"href="styles.css">
<style>
/* Internal CSS */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 1rem;
}
.content {
padding: 1rem;
}
.highlight {
color: #ff5733;
font-weight: bold;
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 0.5rem;
position: fixed;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<header>
<h1>Styling Example: Inline, Internal, and External CSS</h1>
</header>
<mainclass="content">
<h2>Inline Styles</h2>
<pstyle="color: blue; font-size: 18px;">This paragraph uses
<strong>inline styles</strong> to set the text color to blue and increase the
font size.</p>
<h2>Internal Styles</h2>
<pclass="highlight">This paragraph uses a <strong>class
selector</strong> defined in the internal stylesheet to apply specific
styles.</p>
<h2>External Styles</h2>
<pclass="external">This paragraph uses styles defined in an external
stylesheet. Check the linked <code>styles.css</code> file for details.</p>
</main>
<footer>
<p>© 2024 Styling Example. All rights reserved.</p>
</footer>
</body>
</html>
4.A <!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>CSS Selector Types</title>
<linkrel="stylesheet"href="style.css">
</head>
<body>
<!-- Element Selector -->
<h1>Element Selector Example</h1>
<p>This is a paragraph styled using an element selector.</p>
/* ID Selector */
#unique-box {
background-color: lightgreen;
border: 2pxsolidgreen;
padding: 10px;
width: fit-content;
margin: 10pxauto;
}
/* Class Selector */
.highlight {
color: white;
background-color: orange;
padding: 5px;
border-radius: 5px;
}
/* Group Selector */
h2, h3 {
color: darkred;
font-family: 'Arial', sans-serif;
}
/* Universal Selector */
.container* {
font-style: italic;
color: purple;
}
4.B Combinatorselector(descendant,child,adjacentsibling,generalsibling)
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>CSS Combinator Selectors</title>
<linkrel="stylesheet"href="style2.css">
</head>
<body>
<divclass="container">
<h1>Main Heading</h1>
<pclass="intro">This is an introductory paragraph.</p>
<divclass="child-container">
<h2>Child Heading</h2>
<p>This is a child paragraph inside the child container.</p>
</div>
<h2>Another Heading</h2>
<pclass="sibling">This paragraph is a general sibling of the second
heading.</p>
<p>This paragraph is an adjacent sibling of the second heading.</p>
</div>
</body>
</html>
4.C Pseudo-classselector
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Pseudo-class Selector Example</title>
<style>
/* Pseudo-class for hover effect */
button:hover {
background-color: #4CAF50;
color: white;
}
ulli:nth-child(even) {
background-color: #d0d0d0;
}
<h2>Hover Effect</h2>
<button>Hover over me!</button>
<h2>nth-child Selector</h2>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
<h2>Focus Effect</h2>
<inputtype="text"placeholder="Click to focus" />
</body>
</html>
4.D Pseudo-elementselector
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Pseudo-Element Selector Example</title>
<style>
/* Styling a block element with ::before and ::after */
.title {
font-family: Arial, sans-serif;
font-size: 24px;
color: #333;
position: relative;
margin: 20px 0;
}
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Color References in CSS</title>
<style>
/* Named Color */
.named-color {
background-color: coral;
}
/* Hexadecimal Color */
.hex-color {
background-color: #3498db;
}
/* RGB Color */
.rgb-color {
background-color: rgb(46, 204, 113);
}
/* RGBA Color (with transparency) */
.rgba-color {
background-color: rgba(241, 85, 127, 0.7);
}
/* HSL Color */
.hsl-color {
background-color: hsl(120, 100%, 25%);
}
<divclass="named-color">
<p>Named Color: coral</p>
</div>
<divclass="hex-color">
<p>Hex Color: #3498db</p>
</div>
<divclass="rgb-color">
<p>RGB Color: rgb(46, 204, 113)</p>
</div>
<divclass="rgba-color">
<p>RGBA Color: rgba(241, 85, 127, 0.7)</p>
</div>
<divclass="hsl-color">
<p>HSL Color: hsl(120, 100%, 25%)</p>
</div>
<divclass="hsla-color">
<p>HSLA Color: hsla(120, 100%, 25%, 0.5)</p>
</div>
</body>
</html>
5.B WriteaprogramusingthefollowingtermsrelatedtoCSSfontandtext:
i. font-size ii.font-weight iii.font-style
iv.text-decoration v.text-transformation vi.text-alignment
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>CSS Font and Text Example</title>
<style>
/* Style the body */
body {
font-family: Arial, sans-serif;
}
5.C Writeaprogram,toexplaintheimportanceofCSSBoxmodelusing
ii. Content ii.Border iii.Margin iv.padding
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>CSS Box Model Demo</title>
<style>
.box {
width: 200px;
height: 200px;
background-color: lightblue;
text-align: center;
line-height: 200px;
font-size: 20px;
border: 5px solid black; /* Border */
padding: 20px; /* Padding */
margin: 30px; /* Margin */
}
.content-box {
background-color: lightgreen;
}
.padding-box {
background-color: lightcoral;
}
.border-box {
background-color: lightyellow;
}
.margin-box {
background-color: lightgray;
}
</style>
</head>
<body>
<divclass="box content-box">
<p>Content</p>
</div>
<divclass="box padding-box">
<p>Padding</p>
</div>
<divclass="box border-box">
<p>Border</p>
</div>
<divclass="box margin-box">
<p>Margin</p>
</div>
</body>
</html>
6.A WriteaprogramtoembedinternalandexternalJavaScriptinawebpage.
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Embedding JavaScript</title>
<style>
body {
font-family: Arial, sans-serif;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Embedding JavaScript Example</h1>
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Different Ways to Display Output</title>
</head>
<body>
<script>
functiongetVoterInfo() {
letname=prompt("Please enter your name:");
letage=prompt("Please enter your age:");
if (name&&age) {
age=parseInt(age);
lettable=document.getElementById("voterTable").getElementsByTagName('tbody')
[0];
letrow=table.insertRow();
row.insertCell(0).textContent=name;
row.insertCell(1).textContent=age;
row.insertCell(2).textContent=eligibility;
} else {
alert("Please enter both your name and age.");
}
}
</script>
</body>
</html>
7.A Writeaprogramusingdocumentobjectpropertiesandmethods.
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Document Object Demo</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
#info { margin-top: 20px; padding: 10px; border: 1px solid black;
background: #f4f4f4; }
.highlight { color: red; font-weight: bold; }
</style>
</head>
<body>
<divid="info"></div>
<h2>Links in this document:</h2>
<ahref="https://www.google.com"class="site-link">Google</a>
<ahref="https://www.bing.com"class="site-link">Bing</a>
<script>
functionshowProperties() {
letinfo=document.getElementById("info");
info.innerHTML=`
<p><strong>Title:</strong>${document.title}</p>
<p><strong>URL:</strong>${document.URL}</p>
<p><strong>Last Modified:</strong>$
{document.lastModified}</p>
<p><strong>Number of Forms:</strong>$
{document.forms.length}</p>
<p><strong>Number of Images:</strong>$
{document.images.length}</p>
<p><strong>Number of Links:</strong>$
{document.links.length}</p>
<p><strong>Cookies:</strong>${document.cookie || "No cookies
set"}</p>
`;
}
functionmodifyDocument() {
document.title="Updated Title";
letlinks=document.getElementsByClassName("site-link");
for (letlinkoflinks) {
link.style.color="blue";
}
}
functionaddElement() {
letnewPara=document.createElement("p");
lettext=document.createTextNode("This is a newly added
paragraph.");
newPara.appendChild(text);
newPara.classList.add("highlight");
document.body.appendChild(newPara);
}
functionreplaceElement() {
letoldElement=document.getElementById("info");
letnewElement=document.createElement("div");
newElement.id="info";
newElement.innerHTML="<p><strong>Replaced Content:</strong> This
section has been replaced!</p>";
document.body.replaceChild(newElement, oldElement);
}
functionremoveElement() {
letelement=document.getElementById("info");
if (element) {
document.body.removeChild(element);
}
}
functionwriteToDocument() {
document.open();
document.write("<h2>Document Write Method Used</h2><p>This
content replaces everything!</p>");
document.close();
}
</script>
</body>
</html>
7.B Writeaprogramusingwindowobjectpropertiesandmethods.
<!DOCTYPE html>
<html>
<head>
<title>Window Object Example</title>
</head>
<body>
<h1>Window Object Properties and Methods</h1>
<buttononclick="openNewWindow()">Open New Window</button>
<buttononclick="closeNewWindow()">Close New Window</button>
<buttononclick="showAlert()">Show Alert</button>
<buttononclick="showConfirm()">Show Confirm</button>
<buttononclick="showPrompt()">Show Prompt</button>
<pid="demo"></p>
<script>
letnewWindow;
functionopenNewWindow() {
newWindow=window.open("", "_blank", "width=200,height=100");
newWindow.document.write("<h1>Hello from new window!</h1>");
}
functioncloseNewWindow() {
if (newWindow) {
newWindow.close();
}
}
functionshowAlert() {
window.alert("This is an alert box!");
}
functionshowConfirm() {
if (window.confirm("Are you sure?")) {
document.getElementById("demo").innerHTML="Confirmed!";
} else {
document.getElementById("demo").innerHTML="Cancelled!";
}
}
functionshowPrompt() {
letperson=window.prompt("Please enter your name:", "Guest");
if (person!=null) {
document.getElementById("demo").innerHTML=
"Hello "+person+"! How are you today?";
}
}
</script>
</body>
</html>
7.C Writeaprogramusingarrayobjectpropertiesandmethods.(SAVE AS JAVASCRIPT PROGRAM)
// Creating an array
letmyArray= [10, 20, 30, 40, 50];
// Using the map() method to create a new array with modified elements
letnewArray=myArray.map(function(element) {
returnelement*2;
});
console.log("New array after map:", newArray); // Output: [10, 80, 100]
// Using the filter() method to create a new array with filtered elements
letfilteredArray=myArray.filter(function(element) {
returnelement>30;
});
console.log("New array after filter:", filteredArray); // Output: [40, 50]
7.D Writeaprogramusingmathobjectpropertiesandmethods.
// Math Properties
console.log("Math.PI:", Math.PI); // Pi value
console.log("Math.E:", Math.E); // Euler's number
console.log("Math.LN2:", Math.LN2); // Natural log of 2
// Trigonometric functions
console.log("Math.sin(Math.PI / 2):", Math.sin(Math.PI/2)); // Sine of 90
degrees
console.log("Math.cos(0):", Math.cos(0)); // Cosine of 0 degrees
console.log("Math.tan(Math.PI / 4):", Math.tan(Math.PI/4)); // Tangent of 45
degrees
// Logarithms
console.log("Math.log(10):", Math.log(10)); // Natural logarithm of 10
console.log("Math.log10(1000):", Math.log10(1000)); // Base 10 logarithm
7.E Writeaprogramusingstringobjectpropertiesandmethods.
// String Properties
letstr="Hello, JavaScript!";
console.log("String Length:", str.length); // Length of the string
// Case conversion
console.log("Uppercase:", str.toUpperCase()); // Convert to uppercase
console.log("Lowercase:", str.toLowerCase()); // Convert to lowercase
// Character access
console.log("Character at index 7:", str.charAt(7)); // Character at index 7
console.log("Character code at index 7:", str.charCodeAt(7)); // Unicode
value
// Substring extraction
console.log("Substring (7, 17):", str.substring(7, 17)); // Extract substring
console.log("Slice (-10, -1):", str.slice(-10, -1)); // Extract using
negative index
// String search
console.log("Index of 'Java':", str.indexOf("Java")); // Find index of
substring
console.log("Last index of 'a':", str.lastIndexOf("a")); // Last occurrence
console.log("Includes 'Script':", str.includes("Script")); // Check if
substring exists
// Trim whitespace
letpaddedStr=" Trim me! ";
console.log("Trimmed string:", paddedStr.trim()); // Remove whitespace
7.F Writeaprogramusingregexobjectpropertiesandmethods.
7. Writeaprogramusingdateobjectpropertiesandmethods.
G
// JavaScript program demonstrating Date object properties and methods
// Date comparisons
letanotherDate=newDate(2023, 5, 20);
console.log("Date Comparison:", currentDate>anotherDate?"Future Date":"Past
Date");
// Get timestamp
console.log("Timestamp:", currentDate.getTime()); // Milliseconds since Jan
1, 1970
// Date arithmetic
lettomorrow=newDate();
tomorrow.setDate(currentDate.getDate() +1);
console.log("Tomorrow's Date:", tomorrow);
letlastWeek=newDate();
lastWeek.setDate(currentDate.getDate() -7);
console.log("Last Week's Date:", lastWeek);
7.H Writeaprogramtoexplainuser-
definedobjectbyusingproperties,methods,accessors,constructorsanddisplay.
// JavaScript program demonstrating User-Defined Object with Properties,
Methods, Accessors, and Constructor
// Method
this.getFullName=function() {
returnthis.firstName+" "+this.lastName;
};
// Accessor (Getter)
Object.defineProperty(this, 'fullName', {
get:function() {
returnthis.firstName+" "+this.lastName;
}
});
// Accessor (Setter)
Object.defineProperty(this, 'fullName', {
set:function(name) {
letparts=name.split(" ");
this.firstName=parts[0];
this.lastName=parts[1];
}
});
}
// Creating an instance of the Person object
letperson1=newPerson("John", "Doe", 30);
8.A Write a program which asks the user to enter three integers, obtains the numbers from
theuserandoutputsHTMLtextthatdisplaysthelargernumberfollowedbythewords“LARGER NUMBER” in an
information message dialog. If the numbers are equal, outputHTMLtextas “EQUALNUMBERS”.
<body>
<script>
// JavaScript program to compare three integers and display the result in an
alert dialog
<body>
<script>
// JavaScript program to display week days using switch case
// Prompt user to enter a number (1-7)
letdayNumber=parseInt(prompt("Enter a number (1-7) to get the corresponding
weekday:"));
sum+=remainder*remainder*remainder;
functioncalculateDenominations(amount) {
letdenominations= [100, 50, 20, 10, 5, 2, 1];
letresult= [];
for (letdenomofdenominations) {
letcount=Math.floor(amount/denom);
if (count>0) {
result.push(`${count} - ${denom}'s`);
amount%=denom;
}
}
returnresult.join(", ");
}
9.A Isitpalindromeornot
.IV
functionisPalindrome(input) {
// Convert the input to a string and remove non-alphanumeric characters
// Also, convert it to lowercase for case-insensitive comparison
constcleanInput=input.toString().replace(/[^a-zA-Z0-9]/g,
'').toLowerCase();
// Reverse the cleaned input and compare it to the original cleaned input
constreversedInput=cleanInput.split('').reverse().join('');
9.B Designa HTML havinga textbox andfour buttonsnamed Factorial,Fibonacci,Prime,and Palindrome. When
abutton is pressed an appropriate function shouldbe called todisplay
I. Factorialofthatnumber
II. Fibonacciseriesuptothatnumber
III. Primenumbersuptothatnumber
IV. Isitpalindromeornot
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Number Operations</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
input {
padding: 10px;
font-size: 18px;
width: 200px;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
margin: 5px;
cursor: pointer;
}
#result {
font-size: 20px;
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<h2>Number Operations</h2>
<inputtype="number"id="numberInput"placeholder="Enter a number">
<br>
<buttononclick="calculateFactorial()">Factorial</button>
<buttononclick="generateFibonacci()">Fibonacci</button>
<buttononclick="findPrimes()">Prime Numbers</button>
<buttononclick="checkPalindrome()">Palindrome</button>
<pid="result"></p>
<script>
// Function to calculate factorial
functioncalculateFactorial() {
letnum=parseInt(document.getElementById("numberInput").value);
if (num<0) {
document.getElementById("result").innerText="Factorial not
defined for negative numbers!";
return;
}
letfact=1;
for (leti=2; i<=num; i++) {
fact*=i;
}
document.getElementById("result").innerText="Factorial: "+fact;
}
9.C Writeaprogramtovalidatethefollowingfieldsinaregistrationpage.
i. Name(startwithalphabetandfollowedbyalphanumericandthelengthshouldnotbelessthan6charac
ters)
ii. Mobile(onlynumbersandlength10digits)
iii. E-mail(shouldcontainformatlikexxxxxxx@xxxxxx.xxx)
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<script>
functionvalidateForm() {
varname=document.getElementById("name").value;
varmobile=document.getElementById("mobile").value;
varemail=document.getElementById("email").value;
varnamePattern= /^[A-Za-z][A-Za-z0-9]{5,}$/;
varmobilePattern= /^\d{10}$/;
varemailPattern= /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
if (!namePattern.test(name)) {
alert("Invalid Name: Must start with an alphabet, followed by
alphanumeric characters, and be at least 6 characters long.");
returnfalse;
}
if (!mobilePattern.test(mobile)) {
alert("Invalid Mobile Number: Must contain exactly 10
digits.");
returnfalse;
}
if (!emailPattern.test(email)) {
alert("Invalid Email: Must follow the format
example@domain.com");
returnfalse;
}
<labelfor="mobile">Mobile:</label>
<inputtype="text"id="mobile"name="mobile"required><br><br>
<labelfor="email">Email:</label>
<inputtype="text"id="email"name="email"required><br><br>
<inputtype="submit"value="Register">
</form>
</body>
</html>