Hands-on exercises · HTML, CSS, JavaScript & React

Day 1: Frontend Development

Build your first webpage, add JavaScript to make an interactive shopping cart, and explore React using the code snippets. Copy or download the source files for each exercise.

Exercise 01 · HTML & CSS

Personal Profile Card

Learn how to create and style a simple webpage.

Get started

  1. Create a project folder.
    Open it in your code editor.
  2. Create index.html.
    Copy the HTML code below and paste it into the file.
  3. Create style.css.
    Copy the CSS code and save it in the same folder.
  4. Open index.html in your browser.
    You should see a profile card like the preview.
Expected resultLive preview

Source code

Copy or download each file.
HTMLindex.html
<!DOCTYPE html>
<html>
<head>
    <title>Personal Profile Card</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div class="card">

        <img src="https://plus.unsplash.com/premium_photo-1690407617542-2f210cf20d7e?fm=jpg&q=60&w=3000&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=NHwxMjA3fDA%3D" alt="Profile photo">

        <h1>Alex Thomas</h1>

        <h3>Aspiring Web Developer</h3>

        <p>Hi! I'm a student who loves technology,
           coding and creating websites.</p>

        <div class="skills">
            <span>HTML</span>
            <span>CSS</span>
        </div>

        <a href="mailto:alex@example.com">Contact Me</a>

    </div>

</body>
</html>
CSSstyle.css
body {
    background: #eef2ff;
    margin: 0;
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.card {
    background: white;
    width: 280px;
    padding: 25px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 4px 15px #00000010;
}

img {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 50%;
}

h1 {
    color: #172033;
}

h3 {
    color: #2563eb;
}

p {
    color: #64748b;
}

.skills {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
}

span {
    background: #e0e7ff;
    color: #3730a3;
    padding: 8px 12px;
    border-radius: 6px;
}

a {
    display: block;
    background: #2563eb;
    color: white;
    font-weight: bold;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
}
Exercise 02 · HTML, CSS & JavaScript

Smart Supermarket

Build an interactive shopping cart with JavaScript. Add products, calculate the total, clear the cart and simulate checkout.

Get started

  1. Create a new folder called supermarket.
    Keep it separate from your profile card project.
  2. Create index.html, style.css and script.js.
    Copy the corresponding code below into each file.
  3. Open index.html in your browser.
    Test the Add to Cart, Clear Cart and Checkout buttons.
Expected resultInteractive preview

Supermarket source code

Copy or download each file.
HTMLindex.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Smart Supermarket</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

  <header>
    <h1>Smart Supermarket</h1>
    <h3>Cart: <span id="count">0</span></h3>
  </header>

  <h2 class="heading">Our Products</h2>

  <div class="products">

    <div class="card">
       <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTd0vj37dCGBmBK_S5mrsv20GG3wOwu_yPJaAZPuD48Qg&s=10"
          alt="Chips">

       <h2>Chips</h2>
       <p>₹20</p>

       <button onclick="addToCart('Chips', 20)">
          Add to Cart
       </button>
     </div>

     <div class="card">
       <img src="https://images.unsplash.com/photo-1511381939415-e44015466834?w=300"
           alt="Chocolate">

       <h2>Chocolate</h2>
       <p>₹40</p>

       <button onclick="addToCart('Chocolate', 40)">
          Add to Cart
       </button>
     </div>

     <div class="card">
       <img src="https://images.unsplash.com/photo-1563636619-e9143da7973b?w=300"
           alt="Milk">

       <h2>Milk</h2>
       <p>₹30</p>

      <button onclick="addToCart('Milk', 30)">
         Add to Cart
      </button>
    </div>

  </div>

  <div class="cart">

    <h2>Your Shopping Cart</h2>

    <ul id="items"></ul>

    <h2>Total: ₹<span id="total">0</span></h2>

    <button onclick="clearCart()">Clear Cart</button>

    <button onclick="checkout()">Checkout</button>

  </div>

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

</body>
</html>
CSSstyle.css
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f1f5f9;
}

header {
  background: #15803d;
  color: white;
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.heading {
  text-align: center;
  margin: 30px;
}

.products {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 25px;
  padding: 20px;
}

.card {
  background: white;
  width: 220px;
  padding: 20px;
  text-align: center;
  border-radius: 12px;
  box-shadow: 0 4px 10px #00000020;
}

img {
  width: 180px;
  height: 180px;
  object-fit: contain;
}

.card p {
  color: green;
  font-size: 22px;
  font-weight: bold;
}

button {
  background: #15803d;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

button:hover {
  background: #166534;
}

.cart {
  background: white;
  max-width: 700px;
  margin: 30px auto;
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 4px 10px #00000020;
}

li {
  padding: 8px;
}
JSscript.js
let count = 0;
let total = 0;

function addToCart(name, price) {

    count++;
    total = total + price;

    document.getElementById("count").textContent = count;

    document.getElementById("total").textContent = total;

    let item = document.createElement("li");

    item.textContent = name + " - ₹" + price;

    document.getElementById("items").appendChild(item);
}

function clearCart() {

    count = 0;
    total = 0;

    document.getElementById("count").textContent = 0;

    document.getElementById("total").textContent = 0;

    document.getElementById("items").innerHTML = "";
}

function checkout() {

    if (count === 0) {
        alert("Your cart is empty!");
    } else {
        alert("Thank you for shopping! Total: ₹" + total);
        clearCart();
    }
}
Exercise 03 · React

React Code Snippets

Use this document for the React hands-on session.

React workshop code

Open the Google Doc to view and copy the React code snippets.

Open React code snippets