SDC Manual With Outputs
SDC Manual With Outputs
catalog and cart pages using CSS3 features, flex and grid.
Code:
Home.html
<section class="flex-item">
<h2>Welcome to Our Shopping Cart App!</h2>
<p>
This is a simple shopping cart web application where you can explore our catalog of products,
add items to your cart, and proceed to checkout.
</p>
<p>
Whether you're looking for electronics, clothing, accessories, or more, we have a wide selection
of products to choose from.
</p>
<p>
Get started by browsing our catalog or log in to view your cart and place an order.
</p>
</section>
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Shopping Cart App</h1>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="catalog.html">Catalog</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
<li><a href="register.html">Register</a></li>
</ul>
</nav>
</header>
<main id="main-content">
<!-- Content will be loaded dynamically -->
</main>
<script src="script.js"></script>
</body>
</html>
Login.html
<section>
<h2>Login</h2>
<form id="login-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
</section>
Register.html
<section>
<h2>Registration</h2>
<form id="registration-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Register</button>
</form>
</section>
Cart.html
<section>
<h2>Cart</h2>
<div class="cart-item">
<img src="images\product1.jpg" alt="1roduct 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<p>Price: $10</p>
<button>Remove</button>
</div>
<div class="cart-item">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<p>Price: $15</p>
<button>Remove</button>
</div>
<!-- Add more cart items here -->
<button>Checkout</button>
</section>
Catalog.html
<section>
<h2>Catalog</h2>
<div class="product">
<img src="images\product1.jpg" alt="Product 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<button>Add to Cart</button>
</div>
<!-- Add more products here -->
</section>
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Shopping Cart App</h1>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="catalog.html">Catalog</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
<li><a href="register.html">Register</a></li>
</ul>
</nav>
</header>
<main id="main-content">
<!-- Content will be loaded dynamically -->
</main>
<script src="script.js"></script>
</body>
</html>
Script.js
document.addEventListener("DOMContentLoaded", function () {
const homeLink = document.getElementById("home-link");
const catalogLink = document.getElementById("catalog-link");
const cartLink = document.getElementById("cart-link");
const mainContent = document.getElementById("main-content");
homeLink.addEventListener("click", function () {
setActiveLink(homeLink);
loadContent("home.html");
});
catalogLink.addEventListener("click", function () {
setActiveLink(catalogLink);
loadContent("catalog.html");
});
cartLink.addEventListener("click", function () {
setActiveLink(cartLink);
loadContent("cart.html");
});
function setActiveLink(activeLink) {
const links = [homeLink, catalogLink, cartLink];
links.forEach(link => {
link.classList.remove("active");
});
activeLink.classList.add("active");
}
function loadContent(page) {
fetch(page)
.then(response => response.text())
.then(html => {
mainContent.innerHTML = html;
});
}
Style.css
/* Reset default margin and padding */
body, h1, h2, h3, ul, li {
margin: 0;
padding: 0;
}
/* Basic styling */
header {
background-color: #333;
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
nav ul {
list-style-type: none;
display: flex;
}
nav ul li {
margin-right: 20px;
}
nav ul li a {
color: white;
text-decoration: none;
}
.flex-item {
background-color: #3498db; /* Blue background color */
color: white; /* Text color */
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 600px;
margin: 0 auto;
}
main {
padding: 20px;
display: grid;
grid-template-columns: 1fr;
grid-gap: 20px;
}
Home.html
<section class="flex-item">
<h2>Welcome to Our Shopping Cart App!</h2>
<p>
This is a simple shopping cart web application where you can explore our catalog of products,
add items to your cart, and proceed to checkout.
</p>
<p>
Whether you're looking for electronics, clothing, accessories, or more, we have a wide selection
of products to choose from.
</p>
<p>
Get started by browsing our catalog or log in to view your cart and place an order.
</p>
</section>
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Shopping Cart App</h1>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="catalog.html">Catalog</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
<li><a href="register.html">Register</a></li>
</ul>
</nav>
</header>
<main id="main-content">
<!-- Content will be loaded dynamically -->
</main>
<script src="script.js"></script>
</body>
</html>
Login.html
<section>
<h2>Login</h2>
<form id="login-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
</section>
Register.html
<section>
<h2>Registration</h2>
<form id="registration-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Register</button>
</form>
</section>
Cart.html
<section>
<h2>Cart</h2>
<div class="cart-item">
<img src="images\product1.jpg" alt="1roduct 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<p>Price: $10</p>
<button>Remove</button>
</div>
<div class="cart-item">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<p>Price: $15</p>
<button>Remove</button>
</div>
<!-- Add more cart items here -->
<button>Checkout</button>
</section>
Catalog.html
<section>
<h2>Catalog</h2>
<div class="product">
<img src="images\product1.jpg" alt="Product 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<button>Add to Cart</button>
</div>
<!-- Add more products here -->
</section>
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Shopping Cart App</h1>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="catalog.html">Catalog</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
<li><a href="register.html">Register</a></li>
</ul>
</nav>
</header>
<main id="main-content">
<!-- Content will be loaded dynamically -->
</main>
<script src="script.js"></script>
</body>
</html>
Script.js
document.addEventListener("DOMContentLoaded", function () {
const homeLink = document.getElementById("home-link");
const catalogLink = document.getElementById("catalog-link");
const cartLink = document.getElementById("cart-link");
const mainContent = document.getElementById("main-content");
homeLink.addEventListener("click", function () {
setActiveLink(homeLink);
loadContent("home.html");
});
catalogLink.addEventListener("click", function () {
setActiveLink(catalogLink);
loadContent("catalog.html");
});
cartLink.addEventListener("click", function () {
setActiveLink(cartLink);
loadContent("cart.html");
});
function setActiveLink(activeLink) {
const links = [homeLink, catalogLink, cartLink];
links.forEach(link => {
link.classList.remove("active");
});
activeLink.classList.add("active");
}
function loadContent(page) {
fetch(page)
.then(response => response.text())
.then(html => {
mainContent.innerHTML = html;
});
}
Style.css
/* Reset default margin and padding */
body, h1, h2, h3, ul, li {
margin: 0;
padding: 0;
}
/* Basic styling */
header {
background-color: #333;
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
nav ul {
list-style-type: none;
display: flex;
}
nav ul li {
margin-right: 20px;
}
nav ul li a {
color: white;
text-decoration: none;
}
.flex-item {
background-color: #3498db; /* Blue background color */
color: white; /* Text color */
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 600px;
margin: 0 auto;
}
main {
padding: 20px;
display: grid;
grid-template-columns: 1fr;
grid-gap: 20px;
}
Program 3: Use JavaScript for doing client – side validation of the pages implemented in the
above program
To implement client-side validation for the login and registration forms using JavaScript, you can add
event listeners to the form submit events. Modify your existing code in script.js to include validation
for the login and registration forms:
Create a New Project:
Open Visual Studio Code.
Create a new folder for your project and open it in Visual Studio Code.
Open a terminal in Visual Studio Code (Ctrl + `) and initialize a new npm project by running:
npm init -y
Install Bootstrap and its dependencies by running:
npm install bootstrap jquery popper.js
Code:
Script.js
document.addEventListener("DOMContentLoaded", function () {
const homeLink = document.getElementById("home-link");
const catalogLink = document.getElementById("catalog-link");
const cartLink = document.getElementById("cart-link");
const mainContent = document.getElementById("main-content");
homeLink.addEventListener("click", function () {
setActiveLink(homeLink);
loadContent("home.html");
});
catalogLink.addEventListener("click", function () {
setActiveLink(catalogLink);
loadContent("catalog.html");
});
cartLink.addEventListener("click", function () {
setActiveLink(cartLink);
loadContent("cart.html");
});
if (!username || !password) {
alert("Please enter both username and password.");
return;
}
// You can also redirect to a login API or perform further actions here
});
// You can also redirect to a registration API or perform further actions here
});
function setActiveLink(activeLink) {
const links = [homeLink, catalogLink, cartLink];
links.forEach(link => {
link.classList.remove("active");
});
activeLink.classList.add("active");
}
function loadContent(page) {
fetch(page)
.then(response => response.text())
.then(html => {
mainContent.innerHTML = html;
});
}
});
Indexbootstrap.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Bootstrap App</title>
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<!-- Your content goes here -->
<h1>Hello, Bootstrap!</h1>
</div>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
</body>
</html>
Home.html
<section class="flex-item">
<h2>Welcome to Our Shopping Cart App!</h2>
<p>
This is a simple shopping cart web application where you can explore our catalog of products,
add items to your cart, and proceed to checkout.
</p>
<p>
Whether you're looking for electronics, clothing, accessories, or more, we have a wide selection
of products to choose from.
</p>
<p>
Get started by browsing our catalog or log in to view your cart and place an order.
</p>
</section>
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Shopping Cart App</h1>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="catalog.html">Catalog</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
<li><a href="register.html">Register</a></li>
</ul>
</nav>
</header>
<main id="main-content">
<!-- Content will be loaded dynamically -->
</main>
<script src="script.js"></script>
</body>
</html>
Login.html
<section>
<h2>Login</h2>
<form id="login-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
</section>
Register.html
<section>
<h2>Registration</h2>
<form id="registration-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Register</button>
</form>
</section>
Cart.html
<section>
<h2>Cart</h2>
<div class="cart-item">
<img src="images\product1.jpg" alt="1roduct 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<p>Price: $10</p>
<button>Remove</button>
</div>
<div class="cart-item">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<p>Price: $15</p>
<button>Remove</button>
</div>
<!-- Add more cart items here -->
<button>Checkout</button>
</section>
Catalog.html
<section>
<h2>Catalog</h2>
<div class="product">
<img src="images\product1.jpg" alt="Product 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 1">
<h3>Product 1</h3>
<p>Description of Product 1.</p>
<button>Add to Cart</button>
</div>
<div class="product">
<img src="images\product1.jpg" alt="Product 2">
<h3>Product 2</h3>
<p>Description of Product 2.</p>
<button>Add to Cart</button>
</div>
<!-- Add more products here -->
</section>
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Shopping Cart App</h1>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="catalog.html">Catalog</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
<li><a href="register.html">Register</a></li>
</ul>
</nav>
</header>
<main id="main-content">
<!-- Content will be loaded dynamically -->
</main>
<script src="script.js"></script>
</body>
</html>
Style.css
/* Reset default margin and padding */
body, h1, h2, h3, ul, li {
margin: 0;
padding: 0;
}
/* Basic styling */
header {
background-color: #333;
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
nav ul {
list-style-type: none;
display: flex;
}
nav ul li {
margin-right: 20px;
}
nav ul li a {
color: white;
text-decoration: none;
}
.flex-item {
background-color: #3498db; /* Blue background color */
color: white; /* Text color */
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 600px;
margin: 0 auto;
}
main {
padding: 20px;
display: grid;
grid-template-columns: 1fr;
grid-gap: 20px;
}
Program 4: Explore the features of ES6 like arrow functions, callbacks, promises, async/await.
Implement an application for reading the weather information from openweathermap.org and
display the information in the form of a graph on the web page
Index.js
const express = require('express');
const request = require('request');
const path = require('path'); // Add this line
const app = express();
const apiKey = '10ebba3a581ae9a59e8a7693271a4969'; // Replace with your OpenWeatherMap API
key
const chartData = {
labels: ['Temperature'],
datasets: [{
label: weather,
data: [temp.toFixed(2)],
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
}]
};
Bookstore.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="year" type="xs:integer"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Bookstore.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstore SYSTEM "bookstore.dtd">
<bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="bookstore.xsd">
<book>
<title>Harry Potter and the Philosopher's Stone</title>
<author>J.K. Rowling</author>
<year>1997</year>
<price>20.00</price>
</book>
<book>
<title>The Hobbit</title>
<author>J.R.R. Tolkien</author>
<year>1937</year>
<price>15.00</price>
</book>
</bookstore>
Program 8: Maintaining the transactional history of any user is very important. Explore the
various session tracking mechanism (Cookies, HTTP Session)
Server.js
// Setting a cookie in Express.js
const express = require('express');
const app = express();
app.get('/set-cookie', (req, res) => {
res.cookie('username', 'john_doe', { maxAge: 900000, httpOnly: true });
res.send('Cookie has been set');
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Program 9:Create a custom server using http module and explore the other modules of Node
JS like OS path, event in Vs code
Server.js
// Importing required modules
const http = require('http');
// Creating a server
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!\n');
});
myEmitter.on('event', () => {
console.log('An event occurred!');
});
myEmitter.emit('event');
Run this application:
In terminal type the following command:
node server.js
Open a web browser and go to http://localhost:3000 to see the "Hello World!" message served
by your custom server.
Program 10: Develop an express web application that can interact with REST API to perform
CRUD operations on student data. (Use Postman)
STEPS TO FOLLOW: To perform CRUD (Create, Read, Update, Delete) operations on student data.
We'll use Postman to test the API endpoints.
First, make sure you have Node.js and npm installed on your system. Then, follow these steps:
Create a new directory for your project:
Open your terminal or command prompt and create a new directory for your project:
mkdir express-student-api
Navigate into the project directory:
cd express-student-api
Initialize a new Node.js project:
Run the following command to create a package.json file
npm init -y
Install Express.js:
Install Express.js as a dependency for your project:
npm install express
Create your main application file:
Create a new file named app.js and add the following code:
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
// Routes
app.get('/students', (req, res) => {
res.json(students);
});