generate a todolist webapp
- User
generate a todolist webapp
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
generate a todolist webapp
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo List App</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background-color: #f5f5f5;
display: flex;
justify-content: center;
padding: 40px 20px;
}
.container {
width: 100%;
max-width: 600px;
background-color: white;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.input-container {
display: flex;
margin-bottom: 20px;
}
#task-input {
flex: 1;
padding: 12px 15px;
border: 1px solid #ddd;
border-radius: 4px 0 0 4px;
outline: none;
font-size: 16px;
}
#add-button {
padding: 12px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 0 4px 4px 0;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
#add-button:hover {
background-color: #45a049;
}
ul {
list-style-type: none;
}
.task-item {
display: flex;
align-items: center;
padding: 12px 15px;
border-bottom: 1px solid #eee;
transition: background-color 0.3s;
}
.task-item:hover {
background-color: #f9f9f9;
}
.task-text {
flex: 1;
margin-left: 10px;
font-size: 16px;
color: #333;
}
.completed .task-text {
text-decoration: line-through;
color: #888;
}
.delete-btn {
color: #e74c3c;
background: none;
border: none;
font-size: 18px;
cursor: pointer;
padding: 0 8px;
}
.empty-message {
text-align: center;
color: #888;
margin-top: 20px;
font-style: italic;
}
</style>
</head>
<body>
<div class="container">
<h1>Todo List</h1>
<div class="input-container">
<input type="text" id="task-input" placeholder="Add a new task...">
<button id="add-button">Add</button>
</div>
<ul id="task-list">
<!-- Tasks will be added here by JavaScript -->
</ul>
<p id="empty-message" class="empty-message">Your list is empty. Add a task to get started!</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const taskInput = document.getElementById('task-input');
const addButton = document.getElementById('add-button');
const taskList = document.getElementById('task-list');
const emptyMessage = document.getElementById('empty-message');
// Load tasks from local storage
let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
// Function to save tasks to local storage
function saveTasks() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
// Function to render tasks
function renderTasks() {
taskList.innerHTML = '';
if (tasks.length === 0) {
emptyMessage.style.display = 'block';
} else {
emptyMessage.style.display = 'none';
tasks.forEach((task, index) => {
const li = document.createElement('li');
li.className = `task-item ${task.completed ? 'completed' : ''}`;
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = task.completed;
checkbox.addEventListener('change', () => toggleTask(index));
const span = document.createElement('span');
span.className = 'task-text';
span.textContent = task.text;
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete-btn';
deleteBtn.innerHTML = '×';
deleteBtn.addEventListener('click', () => deleteTask(index));
li.appendChild(checkbox);
li.appendChild(span);
li.appendChild(deleteBtn);
taskList.appendChild(li);
});
}
}
// Function to add a new task
function addTask() {
const text = taskInput.value.trim();
if (text) {
tasks.push({ text, completed: false });
saveTasks();
renderTasks();
taskInput.value = '';
}
}
// Function to toggle task completion
function toggleTask(index) {
tasks[index].completed = !tasks[index].completed;
saveTasks();
renderTasks();
}
// Function to delete a task
function deleteTask(index) {
tasks.splice(index, 1);
saveTasks();
renderTasks();
}
// Event listeners
addButton.addEventListener('click', addTask);
taskInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addTask();
}
});
// Initial render
renderTasks();
});
</script>
</body>
</html>
Would you like me to explain or break down the code?