-
Notifications
You must be signed in to change notification settings - Fork 14
/
script.js
47 lines (40 loc) · 1.42 KB
/
script.js
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
37
38
39
40
41
42
43
44
45
46
47
// Info date
const dateNumber = document.getElementById('dateNumber');
const dateText = document.getElementById('dateText');
const dateMonth = document.getElementById('dateMonth');
const dateYear = document.getElementById('dateYear');
// Tasks Container
const tasksContainer = document.getElementById('tasksContainer');
const setDate = () => {
const date = new Date();
dateNumber.textContent = date.toLocaleString('es', { day: 'numeric' });
dateText.textContent = date.toLocaleString('es', { weekday: 'long' });
dateMonth.textContent = date.toLocaleString('es', { month: 'short' });
dateYear.textContent = date.toLocaleString('es', { year: 'numeric' });
};
const addNewTask = event => {
event.preventDefault();
const { value } = event.target.taskText;
if(!value) return;
const task = document.createElement('div');
task.classList.add('task', 'roundBorder');
task.addEventListener('click', changeTaskState)
task.textContent = value;
tasksContainer.prepend(task);
event.target.reset();
};
const changeTaskState = event => {
event.target.classList.toggle('done');
};
const order = () => {
const done = [];
const toDo = [];
tasksContainer.childNodes.forEach( el => {
el.classList.contains('done') ? done.push(el) : toDo.push(el)
})
return [...toDo, ...done];
}
const renderOrderedTasks = () => {
order().forEach(el => tasksContainer.appendChild(el))
}
setDate();