Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
<head>
    <title>Habit Tracker</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=DM+Sans&display=swap');

        body {
            font-family: 'DM Sans', sans-serif;
        }

        .habit-tracker {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
        }

        .habit-form {
            margin-bottom: 20px;
        }

        .habit-form label {
            margin-right: 10px;
        }

        .habit-table {
            margin-bottom: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th,
        td {
            padding: 10px;
            text-align: center;
            border: 1px solid #ccc;
        }

        th:first-child {
            color: beige; /* Change the color here */
        }

        th {
            background-color: #f2f2f2;
        }

        .refresh-button {
            background-color: orange;
            color: #fff;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            margin-right: 10px;
        }

        .refresh-button:hover {
            background-color: #ff9800;
        }

        .delete-habit {
            color: red;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="habit-tracker">
        <h1>My UK Tracker 🌎</h1>
      <h4 style="font-weight: normal;">Embrace new cultural behaviors, habits and keep previous ones</h4>
        <div class="habit-form">
            <input type="text" id="habit" name="habit">
            <button onclick="addHabit()">Add</button>
        </div>

        <div class="habit-table">
            <table>
                <thead>
                    <tr>
                        <th>Habit</th>
                        <th>🌞 Monday</th>
                        <th>🧘🏽‍♀️ Tuesday</th>
                        <th>🪜 Wednesday</th>
                        <th>✍🏼 Thursday</th>
                        <th>🐬 Friday</th>
                        <th>🌳 Saturday</th>
                        <th>⛱️ Sunday</th>
                        <th>🗑️ Delete</th>
                    </tr>
                </thead>
                <tbody id="habit-body">
                    <!-- Habit tracker rows will be dynamically added here -->
                </tbody>
            </table>
        </div>

        <button class="refresh-button" onclick="refreshTable()">Refresh</button>
    </div>

    <script>
        var habitList = [];

        function addHabit() {
            var habit = document.getElementById("habit").value.trim();

            if (habit && !habitList.includes(habit)) {
                habitList.push(habit);

                var habitBody = document.getElementById("habit-body");
                var row = habitBody.insertRow(-1); // Insert a row at the end of the table

                var habitCell = row.insertCell(0);
                habitCell.textContent = habit;

                for (var i = 1; i <= 7; i++) {
                    var dayCell = row.insertCell(i);
                    var checkbox = document.createElement("input");
                    checkbox.type = "checkbox";
                    checkbox.className = "task-check";
                    checkbox.addEventListener("change", updateHabitStatus);
                    dayCell.appendChild(checkbox);
                }

                var deleteCell = row.insertCell(8);
                var deleteButton = document.createElement("span");
                deleteButton.innerHTML = "x";
                deleteButton.className = "delete-habit";
                deleteButton.addEventListener("click", deleteRow);
                deleteCell.appendChild(deleteButton);

                // Clear the input field
                document.getElementById("habit").value = "";
            }
        }

        function updateHabitStatus() {
            var checkboxes = document.getElementsByClassName("task-check");

            var row = this.parentNode.parentNode;
            var isComplete = true;

            for (var i = 1; i < checkboxes.length; i++) {
                if (!checkboxes[i].checked) {
                    isComplete = false;
                    break;
                }
            }

            if (isComplete) {
                row.cells[0].style.textDecoration = "line-through";
            } else {
                row.cells[0].style.textDecoration = "none";
            }

            checkAllCompleted();
        }

        function refreshTable() {
            var checkboxes = document.getElementsByClassName("task-check");

            for (var i = 0; i < checkboxes.length; i++) {
                checkboxes[i].checked = false;
            }

            var rows = document.getElementById("habit-body").rows;

            for (var i = 0; i < rows.length; i++) {
                rows[i].cells[0].style.textDecoration = "none";
            }

            stopConfetti();
        }

        function deleteRow() {
            var row = this.parentNode.parentNode;
            var habit = row.cells[0].textContent;

            var index = habitList.indexOf(habit);
            if (index !== -1) {
                habitList.splice(index, 1);
            }

            row.parentNode.removeChild(row);
            checkAllCompleted();
        }

        function checkAllCompleted() {
            var rows = document.getElementById("habit-body").rows;
            var allCompleted = true;

            for (var i = 0; i < rows.length; i++) {
                var checkboxes = rows[i].querySelectorAll(".task-check");
                var isRowComplete = true;

                for (var j = 1; j < checkboxes.length; j++) {
                    if (!checkboxes[j].checked) {
                        isRowComplete = false;
                        break;
                    }
                }

                if (!isRowComplete) {
                    allCompleted = false;
                    break;
                }
            }

            if (allCompleted && rows.length >= 5) {
                startConfetti();
            } else {
                stopConfetti();
            }
        }

        function startConfetti() {
            var confettiContainer = document.querySelector(".confetti-container");

            if (confettiContainer.children.length === 0) {
                var fireworkCount = 30;

                for (var i = 0; i < fireworkCount; i++) {
                    var firework = document.createElement("div");
                    firework.classList.add("firework");
                    confettiContainer.appendChild(firework);
                }

                setTimeout(stopConfetti, 5000);
            }
        }

        function stopConfetti() {
            var confettiContainer = document.querySelector(".confetti-container");
            confettiContainer.innerHTML = "";
        }
    </script>
</body>
</html>


              
            
!

CSS

              
                
              
            
!

JS

              
                ///Best Script
<!DOCTYPE html>
<html>
<head>
    <title>Habit Tracker</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=DM+Sans&display=swap');

        body {
            font-family: 'DM Sans', sans-serif;
        }

        .habit-tracker {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
        }

        .habit-form {
            margin-bottom: 20px;
        }

        .habit-form label {
            margin-right: 10px;
        }

        .habit-table {
            margin-bottom: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th,
        td {
            padding: 10px;
            text-align: center;
            border: 1px solid #ccc;
        }

        th:first-child {
            color: beige; /* Change the color here */
        }

        th {
            background-color: #f2f2f2;
        }

        .refresh-button {
            background-color: orange;
            color: #fff;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            margin-right: 10px;
        }

        .refresh-button:hover {
            background-color: #ff9800;
        }

        .delete-habit {
            color: red;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="habit-tracker">
        <h1>My Japan Tracker 🌎</h1>
      <h4 style="font-weight: normal;">Embrace new cultural behaviors, habits and keep previous ones</h4>
        <div class="habit-form">
            <input type="text" id="habit" name="habit">
            <button onclick="addHabit()">Add</button>
        </div>

        <div class="habit-table">
            <table>
                <thead>
                    <tr>
                        <th>Habit</th>
                        <th>🌞 Monday</th>
                        <th>🧘🏽‍♀️ Tuesday</th>
                        <th>🪜 Wednesday</th>
                        <th>✍🏼 Thursday</th>
                        <th>🐬 Friday</th>
                        <th>🌳 Saturday</th>
                        <th>⛱️ Sunday</th>
                        <th>🗑️ Delete</th>
                    </tr>
                </thead>
                <tbody id="habit-body">
                    <!-- Habit tracker rows will be dynamically added here -->
                </tbody>
            </table>
        </div>

        <button class="refresh-button" onclick="refreshTable()">Refresh</button>
    </div>

    <script>
        var habitList = [];

        function addHabit() {
            var habit = document.getElementById("habit").value.trim();

            if (habit && !habitList.includes(habit)) {
                habitList.push(habit);

                var habitBody = document.getElementById("habit-body");
                var row = habitBody.insertRow(-1); // Insert a row at the end of the table

                var habitCell = row.insertCell(0);
                habitCell.textContent = habit;

                for (var i = 1; i <= 7; i++) {
                    var dayCell = row.insertCell(i);
                    var checkbox = document.createElement("input");
                    checkbox.type = "checkbox";
                    checkbox.className = "task-check";
                    checkbox.addEventListener("change", updateHabitStatus);
                    dayCell.appendChild(checkbox);
                }

                var deleteCell = row.insertCell(8);
                var deleteButton = document.createElement("span");
                deleteButton.innerHTML = "x";
                deleteButton.className = "delete-habit";
                deleteButton.addEventListener("click", deleteRow);
                deleteCell.appendChild(deleteButton);

                // Clear the input field
                document.getElementById("habit").value = "";
            }
        }

        function updateHabitStatus() {
            var checkboxes = document.getElementsByClassName("task-check");

            var row = this.parentNode.parentNode;
            var isComplete = true;

            for (var i = 1; i < checkboxes.length; i++) {
                if (!checkboxes[i].checked) {
                    isComplete = false;
                    break;
                }
            }

            if (isComplete) {
                row.cells[0].style.textDecoration = "line-through";
            } else {
                row.cells[0].style.textDecoration = "none";
            }

            checkAllCompleted();
        }

        function refreshTable() {
            var checkboxes = document.getElementsByClassName("task-check");

            for (var i = 0; i < checkboxes.length; i++) {
                checkboxes[i].checked = false;
            }

            var rows = document.getElementById("habit-body").rows;

            for (var i = 0; i < rows.length; i++) {
                rows[i].cells[0].style.textDecoration = "none";
            }

            stopConfetti();
        }

        function deleteRow() {
            var row = this.parentNode.parentNode;
            var habit = row.cells[0].textContent;

            var index = habitList.indexOf(habit);
            if (index !== -1) {
                habitList.splice(index, 1);
            }

            row.parentNode.removeChild(row);
            checkAllCompleted();
        }

        function checkAllCompleted() {
            var rows = document.getElementById("habit-body").rows;
            var allCompleted = true;

            for (var i = 0; i < rows.length; i++) {
                var checkboxes = rows[i].querySelectorAll(".task-check");
                var isRowComplete = true;

                for (var j = 1; j < checkboxes.length; j++) {
                    if (!checkboxes[j].checked) {
                        isRowComplete = false;
                        break;
                    }
                }

                if (!isRowComplete) {
                    allCompleted = false;
                    break;
                }
            }

            if (allCompleted && rows.length >= 5) {
                startConfetti();
            } else {
                stopConfetti();
            }
        }

        function startConfetti() {
            var confettiContainer = document.querySelector(".confetti-container");

            if (confettiContainer.children.length === 0) {
                var fireworkCount = 30;

                for (var i = 0; i < fireworkCount; i++) {
                    var firework = document.createElement("div");
                    firework.classList.add("firework");
                    confettiContainer.appendChild(firework);
                }

                setTimeout(stopConfetti, 5000);
            }
        }

        function stopConfetti() {
            var confettiContainer = document.querySelector(".confetti-container");
            confettiContainer.innerHTML = "";
        }
    </script>
</body>
</html>


              
            
!
999px

Console