Lab Webd Rachna
Lab Webd Rachna
NAME : RACHNA
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q1. Create an html page named as “: Basic_Html_Tags.html” Add the following tags
detail.
1. Set the title of the page as “Basic Html Tags”
2. Within the body perform the following
a) Moving text = “Basic HTML Tags”
b) Different heading tags ( h1 to h6)
c) Paragraph
d) Horizontal line
e) Line Break
f) Block Quote
g) Pre tag
h) Different Logical Style ( <b>, <u>, <sub>, <sup>....)
i) Different Physical style ( <code>, <del>, <kbd>...)
j) Listing tags ( 2 types with, & each type provide different “type” attribute)
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic HTML Tags</title>
</head>
<body>
<h1><marquee>Basic HTML Tags</marquee></h1>
<h1>Paragraph</h1>
<h2>Horizontal Line</h2>
<h3>Line Break</h3>
<h4>Block Quote</h4>
<h5>Pre tag</h5>
<h6>Listing tags</h6>
<p>HTML stands for HyperText Markup Language. It is the standard markup language
used to create web pages. HTML is a combination of Hypertext and Markup language.
Hypertext defines the link between web pages. A markup language is used to define the
text document within the tag to define the structure of web pages.</p>
<hr>
<br>
<p><blockquote>This language is used to annotate (make notes for the computer) text
so that a machine can understand it and manipulate text accordingly. Most markup
languages (e.g. HTML) are human-readable. The language uses tags to define what
manipulation has to be done on the text.</blockquote></p>
<p><b>Different logical style</b></p>
<p><u>Different logical style</u></p>
<p><code>Different Physical Style</code></p>
<p><del>Different Physical Style</del></p>
<p><kbd>Different Physical Style</kbd></p>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q2. Create a simple html file to demonstrate the use of different HTML tags(List,
Table).
2.1.Nested ordered list.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LIST</title>
</head>
<body>
<h4>Here is a nested ordered list:</h4>
<ol type="I">
<li>Module 1</li>
<li>Module 2</li>
<ol type="i">
<li>Module 2.1</li>
<li>Module 2.2</li>
</ol>
<li>Module 3</li>
</ol>
<h5>Disc bullets list:</h5>
<ul style="list-style-type: disc;">
<li>keyboard</li>
<li>mouse</li>
<li>monitor</li>
</ul>
<h5>Circle bullets list:</h5>
<ul style="list-style-type: circle;">
<li>CRT</li>
<li>LCD</li>
<li>LED</li>
</ul>
<h5>Square bullets list:</h5>
<ul style="list-style-type: square;">
<li>Windows</li>
<li>Linux</li>
<li>Android</li>
</ul>
<h5>A Definition List:</h5>
<dl>
<dt>Coffee</dt>
<dd>Black Coffee OR Milk Coffee</dd>
<dt>Milk</dt>
<dd>Hot White milk OR Cold Chocolate Milk</dd>
</dl>
</body>
</html>
Q2.2. Time Table
<html>
<head>
<title>TIME-TABLE</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<p align="center"><b>GRAPHIC ERA DEEMED TO BE UNIVERSITY <br> TIME
TABLE OF B.TECH.VIth SEMESTER-COMPUTER SCIENCE & ENGG.-H <br>
ACADEMIC YEAR 2023-24</b> </p>
<p align="left"><b>Room No.:-LT-7</b></p>
<table >
<tr>
<th></th>
<th >8:05-9:00</th>
<th >9:00-9:55</th>
<th>9:55-10:50</th>
<th>11:00-12:00</th>
<th>12:05-01:00</th>
<th>1:00-1:55</th>
<th>1:55-2:50</th>
<th>3:10-4:00</th>
<th>4:00-4:55</th>
<th>4:55-5:50</th>
</tr>
<tr>
<th>Mon</th>
<td colspan="2"> SWAYAM/Training/Extra Curricular Activities/LIB</td>
<td align="center"><mark>TCS-693 <br>LT-7</td>
<td colspan="2" align="center">Placement Preparation Classes<br>LT-7</td>
<td>LUNCH</td>
<td colspan="2" align="center">Software Engineering Lab<br><b>Digital Lab-
1</b></td>
<td align="center"><mark>TCS-601<br><b>LT-5</b></td>
<td align="center"><mark>TCS-601<br><b>LT-5</b></td>
</tr>
<tr>
<th>Tue</th>
<td colspan="2" align="center"><mark >TCS-611<br>(<b>Online</b>)</td>
<td colspan="2" align="center">SWAYAM/Training/Extra Curricular
Activities/LIB</td>
<td>LUNCH</td>
<td align="center"><mark>TCS-693 <br>LT-7</td>
<td colspan="2" align="center">Web Development
Lab(<b>G1</b>)<br><b>New Lab-1</b> <br>Compiler Design
Lab(<b>G2</b>)<br><b>New Lab-2</b></td>
<td align="center"><mark><b>Elective</b></td>
<td align="center"><mark><b>Elective</b></td>
</tr>
<tr>
<th>Wed</th>
<td colspan="2" align="center">Competitive<br>Programming<br>(TOC-601)-
Audit<br>Course<br>(Online)</td>
<td align="center">LIB</td>
<td colspan="2" align="center">Placement Preparation Classes<br>LT-7</td>
<td>LUNCH</td>
<td colspan="2" align="center">Web Development Lab(<b>G2</b>)<br><b>New
Lab-1</b> <br>Compiler Design Lab(<b>G1</b>)<br><b>New Lab-2</b></td>
<td align="center"><mark><b>Elective</b></td>
<td align="center"><mark><b>Elective</b></td>
</tr>
<tr>
<th>Thu</th>
<td align="center"><mark>TCS-604<br>LT-7</td>
<td align="center"><mark>TCS-604<br>LT-7</td>
<td align="center"><mark>TCS-693<br>LT-7</td>
<td align="center"><mark>XCS-601(QAR)<br>LT-7</td>
<td align="center"><mark>TCS-601<br>LT-7</td>
<td align="center">LUNCH</td>
<td colspan="4" align="center">SWAYAM/Training/Extra Curricular
Activities/LIB</td>
</tr>
<tr>
<th>Fri</th>
<td align="center"><mark>TCS-601<br>LT-7</td>
<td align="center"><mark>TCS-693<br>LT-7</td>
<td align="center"><mark>XCS-601(Verbal)<br>LT-7</td>
<td align="center"><mark>XCS-601(Soft Skills)<br>LT-7</td>
<td align="center"><mark>TCS-611<br>(Discussion)<br>LT-7</td>
<td>LUNCH</td>
<td colspan="2" align="center">Software Engineering Lab<br><b>Digital Lab-
1</b></td>
<td align="center"><mark>TCS-604<br>LT-7</td>
<td align="center"><mark>TCS-6044rr4<br>LT-7</td>
</tr>
</table>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q3. Create a simple html file to demonstrate the use of HTML tag(FORM).
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FORMS</title>
</head>
<body bgcolor="lightblue">
<h2 align="center"><font color="brown">ENTRY FORM</font></h2>
<form>
<h4><font color="brown">Enter your Name : </font><input type="text"></h4>
<h4><font color="brown">Enter your Age : </font><input type="text"
size="3"></h4>
<h4><font color="brown">Enter your Address : </font></h4>
<textarea rows="5" cols="30" ></textarea>
<h4><font color="brown">Sex : </font>
<input type="radio"> <font color="brown">Female</font><br>
<input type="radio"> <font color="brown">Male</font>
</h4>
<h4><font color="brown">Nationality : </font>
<select>
<option>(Please select a country)</option>
<option >India</option>
<option>Australia</option>
</select>
</h4>
<h4><font color="brown">Languages Known : </font>
<input type="checkbox" ><font color="brown">C</font><br>
<input type="checkbox"><font color="brown">C++</font><br>
<input type="checkbox"><font color="brown">VB</font><br>
<input type="checkbox"><font color="brown">JAVA</font><br>
<input type="checkbox"><font color="brown">ASP</font><br>
<input type="checkbox"><font color="brown">OTHERS</font><br>
</h4>
<h4><font color="brown">Enter your Password : </font>
<input type="password">
</h4>
<p align="center">
<input type="Submit" value="Reset">
<input type="Submit" value="Submit">
</p>
</form>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q4. Create an html page with different types of frames such as floating frame,
navigation frame & mixed frame.
Q4a. Create an html page named as “frames.html”. Divide the page into two
columns of 20%, 80% size. In 20% size call the hyperlinks for
“navigationframes.html”, “floatingframes.html”, “mixedframe.html”, “noframe”
and make the page to be get displayed on the other column when these links are
clicked.
a. Frames HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FRAMES</title>
</head>
<frameset cols="20%,80%" >
<frame name="first frame" src="mainfile.html"></frame>
<frame name="second frame"></frame>
</frameset>
<body>
</body>
</html>
b. src file-main HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Main file</title>
</head>
<body>
<a href="navigationframe.html" target="frames">navigation frame</a>
<hr>
<a href="floatingframe.html" target="frames">floating frame</a>
<hr>
<a href="noframe.html" target="frames">no frame</a>
<hr>
<a href="mixedframe.html" target="frames">mixed frame</a>
<hr>
</body>
</html>
Q4b. Create an html page named as “navigationframe.html”. Divide the page into
two columns of 40%, 60% size. In 40% size call the hyperlink file created in above
exercise , and make the page to be get displayed on the other column when the link is
clicked.
a. Navigation HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Navigation frame</title>
</head>
<frameset cols="40%, 60%">
<frame name="first frame" src="mainfile.html"></frame>
</frameset>
<body>
</body>
</html>
Q4c .Create an html page named as “floatingframes.html”. In this file include a
paragraph to explain floating frame, and in floating frame include the any html file
created in the above exercise as inline.
a. Floating frame HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLOATING FRAME</title>
</head>
<frameset cols="20%, 80%">
<frame name="first frame" src="mainfile.html"></frame>
<frameset cols="40% , 60%">
<frame name="second frame" src="paragraph.html"></frame>
</frameset>
</frameset>
<body>
</body>
<script>
function addToInput(value) {
document.getElementById("input").value += value;
}
function clearInput() {
document.getElementById("input").value = "";
}
function calculate() {
try {
var input = document.getElementById("input").value;
var result = eval(input);
if (isNaN(result)) {
throw "Invalid expression";
}
document.getElementById("input").value = result;
} catch (error) {
document.getElementById("input").value = error;
}
}
</script>
</body>
</html>
Q7b. Create a HTML page to explain input and output using a scientific calculator
with the use of various predefined functions and objects in JavaScript.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scientific Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: beige;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.calculator {
background-color: #8B4513;
border-radius: 10px;
box-shadow: 5px 5px 15px black;
padding: 20px;
}
input[type="text"] {
width: 100%;
padding: 10px;
font-size: 20px;
text-align: right;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #D2B48C;
}
.button-row {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.button-row input[type="button"] {
flex: 1;
padding: 10px;
font-size: 18px;
margin-right: 5px;
border-radius: 5px;
border: 1px solid #ccc;
background-color: #F5F5DC;
}
.button-row input[type="button"]:last-child {
margin-right: 0;
}
</style>
</head>
<body>
<h1><font color=brown>SIMPLE SCIENTIFIC CALCULATOR</font></h1>
<div class="container">
<div class="calculator">
<input type="text" id="display" readonly>
<div class="button-row">
<input type="button" value="1" onclick="addToDisplay('1')">
<input type="button" value="2" onclick="addToDisplay('2')">
<input type="button" value="3" onclick="addToDisplay('3')">
<input type="button" value="C" onclick="clearDisplay()">
<input type="button" value="<-" onclick="backspace()">
<input type="button" value="=" onclick="calculate()">
</div>
<div class="button-row">
<input type="button" value="4" onclick="addToDisplay('4')">
<input type="button" value="5" onclick="addToDisplay('5')">
<input type="button" value="6" onclick="addToDisplay('6')">
<input type="button" value="-" onclick="addToDisplay('-')">
<input type="button" value="%" onclick="addToDisplay('%')">
<input type="button" value="cos" onclick="addToDisplay('Math.cos(')">
</div>
<div class="button-row">
<input type="button" value="7" onclick="addToDisplay('7')">
<input type="button" value="8" onclick="addToDisplay('8')">
<input type="button" value="9" onclick="addToDisplay('9')">
<input type="button" value="*" onclick="addToDisplay('*')">
<input type="button" value="n!" onclick="calculateFactorial()">
<input type="button" value="sin" onclick="addToDisplay('Math.sin(')">
</div>
<div class="button-row">
<input type="button" value="." onclick="addToDisplay('.')">
<input type="button" value="0" onclick="addToDisplay('0')">
<input type="button" value="," onclick="addToDisplay(',')">
<input type="button" value="+" onclick="addToDisplay('+')">
<input type="button" value="/" onclick="addToDisplay('/')">
<input type="button" value="tan" onclick="addToDisplay('Math.tan(')">
</div>
<div class="button-row">
<input type="button" value="E" onclick="addToDisplay('Math.E')">
<input type="button" value="π" onclick="addToDisplay('Math.PI')">
<input type="button" value="x^y" onclick="addToDisplay('**')">
<input type="button" value="(" onclick="addToDisplay('(')">
<input type="button" value=")" onclick="addToDisplay(')')">
<input type="button" value="log" onclick="addToDisplay('Math.log(')">
</div>
<div class="button-row">
<input type="button" value="√" onclick="addToDisplay('Math.sqrt(')">
<input type="button" value="LN2" onclick="addToDisplay('Math.LN2')">
<input type="button" value="LN10" onclick="addToDisplay('Math.LN10')">
<input type="button" value="log2E" onclick="addToDisplay('Math.LOG2E')">
<input type="button" value="log10E" onclick="addToDisplay('Math.LOG10E')">
<input type="button" value="EXP" onclick="addToDisplay('Math.exp(')">
</div>
</div>
</div>
<script>
function addToDisplay(value) {
document.getElementById("display").value += value;
}
function clearDisplay() {
document.getElementById("display").value = "";
}
function backspace() {
var display = document.getElementById("display");
display.value = display.value.slice(0, -1);
}
function calculate() {
try {
var expression = document.getElementById("display").value;
var result = eval(expression);
document.getElementById("display").value = result;
} catch (error) {
document.getElementById("display").value = "Error";
}
}
function calculateFactorial() {
var expression = document.getElementById("display").value;
var num = parseInt(expression);
if (isNaN(num) || num < 0) {
document.getElementById("display").value = "Error";
return;
}
var factorial = 1;
for (var i = 2; i <= num; i++) {
factorial *= i;
}
document.getElementById("display").value = factorial;
}
</script>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q8. Create a html page to explain the use of various predefined functions in window
object in java script. Window Object methods alert() , prompt() , confirm(), open(),
close() , print() . Create an html page named as “window.html” and within the script
tag use different window object.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Window Object Functions in JavaScript</title>
</head>
<body>
<h1>Demonstrating Window Object Functions in JavaScript</h1>
<p>Click the buttons below to see various window object functions in action:</p>
<button onclick="showAlert()">Show Alert</button>
<button onclick="getPrompt()">Prompt for Input</button>
<button onclick="showConfirm()">Confirm Action</button>
<button onclick="openNewWindow()">Open New Window</button>
<button onclick="closeNewWindow()">Close New Window</button>
<button onclick="printPage()">Print This Page</button>
<script>
// 1. Alert
function showAlert() {
window.alert("This is an alert message!");
}
// 2. Prompt
function getPrompt() {
const userInput = window.prompt("Enter your name:");
if (userInput) {
window.alert("Hello, " + userInput + "!");
}
}
// 3. Confirm
function showConfirm() {
const userConfirmed = window.confirm("Do you want to continue?");
if (userConfirmed) {
window.alert("You chose to continue.");
} else {
window.alert("You chose to stop.");
}
}
let newWindow = null; // Variable to hold the reference to the new window
// 4. Open a New Window
function openNewWindow() {
if (!newWindow || newWindow.closed) {
newWindow = window.open("", "_blank", "width=400,height=400");
newWindow.document.write("<h2>This is a new window!</h2>");
}
}
// 5. Close the New Window
function closeNewWindow() {
if (newWindow && !newWindow.closed) {
newWindow.close();
} else {
window.alert("No open window to close.");
}
}
// 6. Print
function printPage() {
window.print();
}
</script>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q9. Event Handling - Background Color Change
Create an html page to change the background color for every click of a button
using javascript.
Problem Statement:
1. Create a html page named as changebackground_color.html
2. Define a method named as random_color() which is to be called when you click on
the body. This method should generate random number, which is used to set the
background color.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
button{
padding: 10px 20px;
margin : 100px;
cursor:pointer;
color:blue;
}
</style>
</head>
<body onclick="random_color()">
<button onclick="random_color()">Click to change background color</button>
<script>
function random_color()
{
let red=Math.floor(Math.random()*256);
let green=Math.floor(Math.random()*256);
let blue=Math.floor(Math.random()*256);
document.body.style.backgroundColor=`rgb(${red},${green},${blue})`;
}
</script>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q10. Event Handling - calendar for the month and year by combo box
Create an html page with 2 combo box populated with month & year, to display the
calendar for the selected month & year from combo box using javascript.
Problem Statement: Create a html file named as “Claendar_month.html”
1. Add two combo box one to display month & another for year and one button.
2. When the button is clicked display the calendar for the selected values.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calendar</title>
<style>
.calendar {
border-collapse: collapse;
width: 50%;
margin-top: 20px;
}
.calendar th, .calendar td {
border: 1px solid #ddd;
text-align: center;
padding: 8px;
}
.calendar th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Calendar</h1>
<script>
function getDaysInMonth(month, year) {
return new Date(year, month, 0).getDate();
}
function displayCalendar() {
const month = parseInt(document.getElementById("month").value);
const year = parseInt(document.getElementById("year").value);
const calendarContainer = document.getElementById("calendar-container");
calendarContainer.innerHTML = "";
if(min<10)
{
min="0"+min;
}
if(sec<10)
{
sec="0"+sec;
}
let currentTime="Current time is "+hrs+m+" : "+min+" : "+sec;
document.write(currentTime);
</script>
</body>
</html>
Q11b. Write a JavaScript program to get the current date. Expected Output : mm-dd-yyyy,
mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Current Date Formats</title>
</head>
<body>
<h1>Current Date in Different Formats</h1>
<div id="output">
</div>
<script>
function getCurrentDate() {
const now = new Date();
const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0');
const year = now.getFullYear();
const mm_dd_yyyy = `${month}-${day}-${year}`;
const mm_slash_dd_yyyy = `${month}/${day}/${year}`;
const dd_mm_yyyy = `${day}-${month}-${year}`;
const dd_slash_mm_yyyy = `${day}/${month}/${year}`;
return {
"mm-dd-yyyy": mm_dd_yyyy,
"mm/dd/yyyy": mm_slash_dd_yyyy,
"dd-mm-yyyy": dd_mm_yyyy,
"dd/mm/yyyy": dd_slash_mm_yyyy
};
}
function displayCurrentDate() {
const currentDate = getCurrentDate();
const output = document.getElementById("output");
const dateStrings = `
<p>mm-dd-yyyy: ${currentDate["mm-dd-yyyy"]}</p>
<p>mm/dd/yyyy: ${currentDate["mm/dd/yyyy"]}</p>
<p>dd-mm-yyyy: ${currentDate["dd-mm-yyyy"]}</p>
<p>dd/mm/yyyy: ${currentDate["dd/mm/yyyy"]}</p>
`;
output.innerHTML = dateStrings;
}
window.onload = displayCurrentDate;
</script>
</body>
</html>
Q11c. Write a JavaScript function to get difference between two dates in days.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Difference Between Two Dates in Days</title>
</head>
<body>
<h1>Calculate Difference Between Two Dates in Days</h1>
<label for="date1">Enter the first date (MM/DD/YYYY):</label>
<input type="text" id="date1" value="04/02/2014" /> <br>
<label for="date2">Enter the second date (MM/DD/YYYY):</label>
<input type="text" id="date2" value="11/04/2014" /> <br>
<button onclick="calculateDateDifference()">Calculate Difference</button>
<div id="result"></div>
<script>
function date_diff_in_days(date1, date2) {
const d1 = new Date(date1);
const d2 = new Date(date2);
const diffInMilliseconds = d2 - d1;
const diffInDays = diffInMilliseconds / (1000 * 60 * 60 * 24);
return Math.round(diffInDays);
}
function calculateDateDifference() {
const date1 = document.getElementById("date1").value;
const date2 = document.getElementById("date2").value;
const daysDifference = date_diff_in_days(date1, date2);
document.getElementById("result").innerHTML = `The difference between the
dates is ${daysDifference} days.`;
}
</script>
</body>
</html>
Q11d. . Write a JavaScript function to count the number of days passed since
beginning of the year.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Days Passed Since Start of Year</title>
</head>
<body>
<h1>Days Passed Since Beginning of the Year</h1>
<label for="date">Enter a date (MM/DD/YYYY):</label>
<input type="text" id="date" value="01/15/2015" />
<button onclick="calculateDaysPassed()">Calculate Days Passed</button>
<div id="result"></div>
<script>
function days_passed(date) {
const givenDate = new Date(date);
const startOfYear = new Date(givenDate.getFullYear(), 0, 1);
const diffInMilliseconds = givenDate - startOfYear;
const diffInDays = diffInMilliseconds / (1000 * 60 * 60 * 24);
return Math.round(diffInDays);
}
function calculateDaysPassed() {
const dateInput = document.getElementById("date").value;
const days = days_passed(dateInput);
document.getElementById("result").innerHTML = `Number of days passed since
the beginning of the year: ${days}`;
}
</script>
</body>
</html>
Q11e. Write a JavaScript program to find 1st January is being a Sunday between
year1 and year2.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>January 1 as Sunday</title>
</head>
<body>
<h1>Years Where January 1 Is a Sunday</h1>
<label for="startYear">Start Year:</label>
<input type="number" id="startYear" value="2000" />
<label for="endYear">End Year:</label>
<input type="number" id="endYear" value="2030" />
<br><br>
<button onclick="findYearsWithSunday()">Find Years</button>
<br><br>
<div id="result"></div>
<script>
function findYearsWithSunday() {
const startYear = parseInt(document.getElementById("startYear").value);
const endYear = parseInt(document.getElementById("endYear").value);
const yearsWithSunday = [];
for (let year = startYear; year <= endYear; year++) {
const jan1 = new Date(year, 0, 1);
if (jan1.getDay() === 0) {
yearsWithSunday.push(year);
}
}
if (yearsWithSunday.length > 0) {
document.getElementById("result").innerHTML =
`Years where January 1 is a Sunday between ${startYear} and ${endYear}: $
{yearsWithSunday.join(", ")}`;
} else {
document.getElementById("result").innerHTML =
`No years between ${startYear} and ${endYear} have January 1 falling on a
Sunday.`;
}
}
</script>
</body>
</html>
Q11f. Write a JavaScript program to calculate days left until next Christmas.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Days Until Next Christmas</title>
</head>
<body>
<h1>Days Left Until Next Christmas</h1>
<button onclick="calculateDaysUntilChristmas()">Find days</button>
<div id="result"></div>
<script>
function calculateDaysUntilChristmas() {
const today = new Date();
let christmasThisYear = new Date(today.getFullYear(), 11, 25);
if (today > christmasThisYear) {
christmasThisYear = new Date(today.getFullYear() + 1, 11, 25);
}
const diffInMilliseconds = christmasThisYear - today;
const daysLeft = Math.ceil(diffInMilliseconds / (1000 * 60 * 60 * 24));
document.getElementById("result").innerHTML = `There are ${daysLeft} days
left until next Christmas.`;
}
</script>
</body>
</html>
Q11g. Write a JavaScript program to calculate days remains in your birthday.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Days Until Next Birthday</title>
</head>
<body>
<h1>Days Left Until My Next Birthday</h1>
<button onclick="calculateDays()">Find days</button>
<div id="result"></div>
<script>
function calculateDays() {
const today = new Date();
let birthdayThisYear = new Date(today.getFullYear(), 9, 16);
if (today > birthdayThisYear) {
birthdayThisYear = new Date(today.getFullYear() + 1, 11, 25);
}
const diffInMilliseconds = birthdayThisYear - today;
const daysLeft = Math.ceil(diffInMilliseconds / (1000 * 60 * 60 * 24));
document.getElementById("result").innerHTML = `There are ${daysLeft} days
left until my next Birthday.`;
}
</script>
</body>
</html>
/*
NAME : RACHNA KUMARI
SECTION : H
CLASS ROLL NUMBER : 50
UNIVERSITY ROLL NUMBER : 2019023
*/
Q12. Window object method setInterval, clearInterval
Create an html page with three button START PAUSE and RESET for controlling
stopwatch.
Problem Statement: Create a html file named as “stopwatch.html”
1. Add number div display HH MM SS.
2. When the button is clicked START start watch.
3. When the button is clicked PAUSE stop watch.
4. When the button is clicked RESET reset div values 00:00:00.
5. When the button is clicked SAVE LAP save the lap.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stopwatch</title>
<style>
#stopwatch {
font-size: 2em;
text-align: center;
margin: 20px;
color:red;
}
#controls {
display: flex;
justify-content: center;
gap: 10px;
}
#laps {
text-align: center;
margin-top: 10px;
}
</style>
</head>
<body bgcolor="grey">
<h1 align="center">Stopwatch</h1>
<div id="stopwatch">00:00:00</div>
<div id="controls">
<button onclick="startStopwatch()">START</button>
<button onclick="pauseStopwatch()">PAUSE</button>
<button onclick="resetStopwatch()">RESET</button>
<button onclick="saveLap()">SAVE LAP</button>
</div>
<div id="laps"></div>
<script>
let intervalId = null;
let elapsedSeconds = 0;
function startStopwatch() {
if (intervalId === null) {
intervalId = setInterval(incrementTime, 1000);
}
}
function pauseStopwatch() {
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
}
}
function resetStopwatch() {
pauseStopwatch();
elapsedSeconds = 0;
updateDisplay();
}
function saveLap() {
const currentDisplay = document.getElementById("stopwatch").innerHTML;
const lapsDiv = document.getElementById("laps");
lapsDiv.innerHTML += `<div>Lap: ${currentDisplay}</div>`;
}
function incrementTime() {
elapsedSeconds += 1;
updateDisplay();
}
function updateDisplay() {
const hours = Math.floor(elapsedSeconds / 3600);
const minutes = Math.floor((elapsedSeconds % 3600) / 60);
const seconds = elapsedSeconds % 60;
const formattedTime = `${String(hours).padStart(2, '0')}:$
{String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
document.getElementById("stopwatch").innerHTML = formattedTime;
}
</script>
</body>
</html>