Skip to content

CodeMaharathis/Priyanka

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

To create a basic online shopping program in HTML, you’ll need to include some key sections in your documentation. Here’s an example of what such a program might include, with sample code and a simple documentation structure.

Online Shopping Program Documentation


Overview

This online shopping program allows users to browse products, add them to the shopping cart, and proceed to checkout. It is a simple representation of an e-commerce website built using HTML, CSS, and JavaScript. The main functionality is handled with HTML for structure, CSS for styling, and JavaScript for interaction.


Features

  • Display a list of products with images, names, and prices.
  • Add products to the shopping cart.
  • View and update the cart.
  • Calculate the total price of the cart.
  • Simple user interface with basic form inputs.

Technologies Used

  • HTML: Provides the basic structure and content of the web page.
  • CSS: Styles the website to make it user-friendly and visually appealing.
  • JavaScript: Adds interactivity to the site (e.g., adding products to the cart, calculating total prices).

File Structure

/index.html         - Main HTML file for the website
/styles.css         - CSS file for styling
/script.js          - JavaScript file for handling cart functionality
/images/            - Directory for product images

Code Documentation

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Online Shopping</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <h1>Online Shop</h1>
        <nav>
            <a href="#products">Shop</a>
            <a href="#cart">Cart</a>
        </nav>
    </header>

    <!-- Products Section -->
    <section id="products">
        <h2>Our Products</h2>
        <div class="product" id="product1">
            <img src="images/product1.jpg" alt="Product 1">
            <h3>Product 1</h3>
            <p>$10</p>
            <button onclick="addToCart('Product 1', 10)">Add to Cart</button>
        </div>
        <div class="product" id="product2">
            <img src="images/product2.jpg" alt="Product 2">
            <h3>Product 2</h3>
            <p>$15</p>
            <button onclick="addToCart('Product 2', 15)">Add to Cart</button>
        </div>
    </section>

    <!-- Cart Section -->
    <section id="cart">
        <h2>Your Cart</h2>
        <ul id="cartItems"></ul>
        <p>Total: $<span id="totalPrice">0</span></p>
        <button onclick="checkout()">Checkout</button>
    </section>

    <script src="script.js"></script>
</body>
</html>

styles.css

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

header {
    background-color: #333;
    color: white;
    padding: 10px;
    text-align: center;
}

nav a {
    margin: 0 10px;
    color: white;
    text-decoration: none;
}

#products {
    display: flex;
    justify-content: space-around;
    padding: 20px;
}

.product {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: center;
    width: 200px;
}

#cart {
    padding: 20px;
    background-color: #f4f4f4;
}

#cartItems {
    list-style-type: none;
    padding: 0;
}

button {
    background-color: #333;
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
}

button:hover {
    background-color: #555;
}

script.js

let cart = [];
let totalPrice = 0;

function addToCart(productName, price) {
    // Add product to cart
    cart.push({ productName, price });
    totalPrice += price;

    // Update cart display
    updateCartDisplay();
}

function updateCartDisplay() {
    // Update the cart UI
    const cartItemsList = document.getElementById('cartItems');
    cartItemsList.innerHTML = '';
    cart.forEach(item => {
        const li = document.createElement('li');
        li.textContent = `${item.productName} - $${item.price}`;
        cartItemsList.appendChild(li);
    });

    // Update total price
    document.getElementById('totalPrice').textContent = totalPrice;
}

function checkout() {
    if (cart.length === 0) {
        alert('Your cart is empty!');
    } else {
        alert('Proceeding to checkout...');
        // Here you would typically handle the checkout process (e.g., redirect to payment page)
    }
}

How the Code Works

  1. HTML Structure:

    • The HTML file creates the structure for the shopping page, including a header, product listings, and a cart section.
    • The products have "Add to Cart" buttons that trigger the addToCart() function when clicked.
  2. CSS Styling:

    • The styles.css file styles the page layout, ensuring products are displayed in a grid and the cart section is separate.
    • The page elements, such as buttons and product cards, have basic styles applied for better UI/UX.
  3. JavaScript Functionality:

    • The script.js file manages the interactivity. The addToCart() function adds products to an array representing the cart, while updateCartDisplay() updates the UI to reflect the current items in the cart and the total price.
    • The checkout() function simulates the checkout process by alerting the user.

Improvements for a Real-World Application

  • Product Data: In a real application, product data would be dynamically fetched from a database.
  • Payment Gateway Integration: For actual checkout functionality, integration with a payment gateway like PayPal or Stripe would be necessary.
  • Session Management: Using cookies or local storage to persist cart items across page reloads.
  • Mobile Responsiveness: Add media queries to ensure the website is mobile-friendly.

Conclusion

This basic online shopping program demonstrates the core functionality of an e-commerce site, with the ability to display products, add them to a cart, and calculate totals. While it's quite simple, it provides the foundation for further development and can be expanded with more features like user authentication, a full checkout system, and product filtering.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • HTML 56.2%
  • CSS 43.8%