-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (43 loc) · 1.12 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
48
49
50
class Task {
id;
title;
description;
constructor(id, title, description) {
this.id = id;
this.title = title;
this.description = description;
}
}
let Tasks = [];
let id = 0;
let title = document.getElementById('title')
let description = document.getElementById('description')
let tasklist = document.getElementById('tasklist')
atualizaLista = () => {
html = ''
if(Tasks != []) {
Tasks.forEach((value, index) => {
html += `<div class='task'><span>Title:</span> ${value.title} <br> <span>Description:</span> ${value.description} <button onclick="deletar(${value.id})">Remover</button></div>`;
})
}
tasklist.innerHTML = html
}
adicionar = () => {
if(title.value && description.value) {
Tasks.push(new Task(id, title.value, description.value))
id++;
atualizaLista()
}else {
alert('Necessario preencher todos os campos')
}
}
deletar = (obj) => {
console.log(obj)
Tasks = Tasks.filter((value) => {
if (value.id != obj) {
return value
}
})
atualizaLista()
}
atualizaLista()