Git Product home page Git Product logo

js-todolist's Introduction

js-todolist

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>To-Do List</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <h1>Work To-Dos</h1>
        <form id="taskForm">
            <input type="text" id="title" placeholder="Title" required>
            <input type="text" id="description" placeholder="Description" required>
            <input type="date" id="dueDate" required>
            <button type="submit">Add Task</button>
        </form>
        <ul id="taskList"></ul>
    </div>
    <script src="app.js"></script>
</body>
</html>

style.css

body {
    font-family: Arial, sans-serif;
    background-color: #208dd1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.container {
   
    padding: 20px;
    width: 400px;
    max-width: 100%;
}

h1 {
    margin-top: 0;
}

form {
    display: flex;
    flex-direction: column;
}

input, button {
    padding: 10px;
    margin: 5px 0;
    border: 1px solid #ccc;
    border-radius: 4px;
}

button {
    background-color: #28a745;
    color: #fff;
    cursor: pointer;
    border: none;
}

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

ul {
    list-style: none;
    padding: 0;
}

li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #ccc;
}

li.complete {
    text-decoration: line-through;
    color: #888;
}

app.js

class Task {
    constructor(title, description, dueDate) {
        this.title = title;
        this.description = description;
        this.dueDate = dueDate;
        this.completed = false;
    }
}

class ToDoList {
    constructor() {
        this.tasks = JSON.parse(localStorage.getItem('tasks')) || [];
        this.taskList = document.getElementById('taskList');
        this.taskForm = document.getElementById('taskForm');
        this.taskForm.addEventListener('submit', this.addTask.bind(this));
        this.render();
    }

    addTask(event) {
        event.preventDefault();
        const title = document.getElementById('title').value;
        const description = document.getElementById('description').value;
        const dueDate = document.getElementById('dueDate').value;
        const newTask = new Task(title, description, dueDate);
        this.tasks.push(newTask);
        this.saveTasks();
        this.render();
        this.taskForm.reset();
    }

    editTask(index) {
        const title = prompt('Enter new title:', this.tasks[index].title);
        const description = prompt('Enter new description:', this.tasks[index].description);
        const dueDate = prompt('Enter new due date:', this.tasks[index].dueDate);
        if (title && description && dueDate) {
            this.tasks[index].title = title;
            this.tasks[index].description = description;
            this.tasks[index].dueDate = dueDate;
            this.saveTasks();
            this.render();
        }
    }

    deleteTask(index) {
        this.tasks.splice(index, 1);
        this.saveTasks();
        this.render();
    }

    toggleComplete(index) {
        this.tasks[index].completed = !this.tasks[index].completed;
        this.saveTasks();
        this.render();
    }

    saveTasks() {
        localStorage.setItem('tasks', JSON.stringify(this.tasks));
    }

    render() {
        this.taskList.innerHTML = '';
        this.tasks.forEach((task, index) => {
            const taskItem = document.createElement('li');
            taskItem.className = task.completed ? 'complete' : '';
            taskItem.innerHTML = `
                <span>${task.title} - ${task.description} (Due: ${task.dueDate})</span>
                <div>
                    <button onclick="toDoList.toggleComplete(${index})">${task.completed ? 'Incomplete' : 'Complete'}</button>
                    <button onclick="toDoList.editTask(${index})">Edit</button>
                    <button onclick="toDoList.deleteTask(${index})">Delete</button>
                </div>
            `;
            this.taskList.appendChild(taskItem);
        });
    }
}

const toDoList = new ToDoList();

package-lock.json

{
    "name": "javascript-project",
    "lockfileVersion": 3,
    "requires": true,
    "packages": {}
  }

output

Screenshot 2024-07-08 085046 Screenshot 2024-07-08 085141

js-todolist's People

Contributors

srivarshan123 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.