Project Setup & Verifying JavaScript Loading

What this lesson is about

Before touching the DOM or HTML elements, we must first answer a fundamental question:

“Is my JavaScript file actually loading and executing?”

In real-world applications, 50% of bugs come from scripts:

  • not loading

  • loading in wrong order

  • being overridden

  • or failing silently

So in this lesson, we will:

  • Set up a clean project structure

  • Connect HTML, CSS, and JavaScript

  • Verify JavaScript execution using console.log

Step 1: Create the Project Structure

Create a folder called:

javascript-basics/

Inside it, create the following files:

javascript-basics/
│
├── index.html
├── styles.css
└── script.js

This separation is mandatory for scalable applications.

Step 2: Add HTML (index.html)

Paste the following into index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spiritual Diary</title>

    <!-- JavaScript file -->
    <script src="./script.js"></script>

    <!-- CSS file -->
    <link rel="stylesheet" href="./styles.css">
</head>

<body>
    <h3>Spiritual Diary</h3>

    <ul class="activity-list">
        <li>
            <div class="task-completed">
                <input type="checkbox" />
            </div>
            <div class="activity-label">Surya Namskaram</div>
            <div class="start-time-range">6:00 AM - 7:00 AM</div>
        </li>
        <li>
            <div class="task-completed">
                <input type="checkbox" id="task2"/>
            </div>
            <div class="activity-label">
                Task 1
            </div>
            <div class="start-time-range">
                8:00 AM - 9:00 AM
            </div>       
        </li>
        <li>
            <div class="task-completed">
                <input type="checkbox" id="task3"/>
            </div>
            <div class="activity-label">
                Task 2
            </div>
            <div class="start-time-range">
                10:00 AM - 11:00 AM
            </div>
        </li>
        
        <li>
            <div class="task-completed">
                <input type="checkbox" id="task5"/>
            </div>
            <div class="activity-label">
                Task 3
            </div>
            <div class="start-time-range">
                6:00 PM - 7:00 PM
            </div>
        </li>
    </ul>
</body>
</html>

👉 At this stage, HTML is static.
👉 We are not interacting with it yet.

Step 3: Add CSS (styles.css)

Paste this into styles.css:

/* ---------- Base Reset ---------- */
    * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    }

    body {
        background-color: #f8f6f3;
        padding: 20px;
        color: #2b2b2b;
    }

    /* ---------- Header ---------- */
    h3 {
        text-align: center;
        margin-bottom: 20px;
        color: #7A1E3A;
    }

    /* ---------- Activity List ---------- */
    .activity-list {
        list-style: none;
        max-width: 650px;
        margin: 0 auto;
    }

    /* ---------- Activity Item ---------- */
    .activity-list li {
        background-color: #ffffff;
        border-radius: 8px;
        padding: 12px 16px;
        margin-bottom: 12px;

        display: grid;
        grid-template-columns: 40px 1fr auto;
        align-items: center;

        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
        transition: box-shadow 0.15s ease, transform 0.15s ease;
    }

    .activity-list li:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    }

    /* ---------- Checkbox ---------- */
    .task-completed {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .task-completed input[type="checkbox"] {
        width: 18px;
        height: 18px;
        cursor: pointer;
    }

    /* ---------- Activity Label ---------- */
    .activity-label {
        font-weight: 600;
    }

    /* ---------- Time Range ---------- */
    .start-time-range {
        font-size: 0.9rem;
        color: #555;
        white-space: nowrap;
    }

    /* ---------- Completed State (future JS hook) ---------- */
    .activity-list li.completed {
        opacity: 0.6;
    }

    .activity-list li.completed .activity-label {
        text-decoration: line-through;
    }

This confirms:

  • CSS is loading

  • File linking works

Step 4: Add JavaScript (script.js)

Paste only this into script.js:

console.log("JavaScript file loaded successfully");

That’s it. Nothing else.

Step 5: Verify JavaScript Execution

  1. Open index.html in Chrome

  2. Right-click → Inspect

  3. Open the Console tab

You should see:

JavaScript file loaded successfully

🎉 This confirms:

  • The script file is connected
  • The browser executed JavaScript
  • No errors occurred

Why We Start Like This (Very Important)

In enterprise applications:

  • Scripts are bundled
  • Loaded conditionally
  • Injected dynamically
  • Cached aggressively

If you don’t know how to verify execution, debugging becomes guesswork.

This lesson builds the habit of:

  • checking console
  • verifying execution
  • isolating problems