-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
36 lines (31 loc) · 1.1 KB
/
scripts.js
File metadata and controls
36 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function setRandomGradientBackground() {
const gradients = [
'linear-gradient(to right, #0f2027, #203a43, #2c5364)',
'linear-gradient(to right, #434343, #000000)',
'linear-gradient(to right, #4568dc, #b06ab3)',
'linear-gradient(to right, #4A00E0, #8E2DE2)',
]
document.body.style.background = gradients[Math.floor(Math.random() * gradients.length)];
}
document.getElementById('todo-input').addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
addTodo();
}
});
function addTodo() {
let todoList = document.getElementById('todo-list');
let todoInput = document.getElementById('todo-input');
let newTodoText = todoInput.value;
if (newTodoText.trim() !== '') {
let newLi = document.createElement('li');
newLi.textContent = newTodoText;
newLi.addEventListener('click', function() {
this.classList.toggle('done');
});
todoList.appendChild(newLi);
todoInput.value = '';
}
}
document.addEventListener('DOMContentLoaded', function() {
setRandomGradientBackground();
});