-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunciones.js
61 lines (54 loc) · 2.08 KB
/
funciones.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
51
52
53
54
55
56
57
58
59
60
61
let arrayWorks = [];
let id = 0;
let refresh = () => {
let ul = document.getElementById("listWorks")
document.getElementById("listWorks").innerHTML = "";
for (let index = 0; index <= arrayWorks.length; index++) {
if (arrayWorks[index].status) {
ul.innerHTML += `
<li><input class="Input" type="checkbox" onclick="through('${arrayWorks[index].idCheck}')" id="${arrayWorks[index].idCheck}">
<label class="form-check-label incorrecto" for="defaultCheck1" id="${arrayWorks[index].idLabel}">
${arrayWorks[index].textContent}
</label></input>
</li>
`
} else {
ul.innerHTML += `<li><input class="Input" type="checkbox" onclick="through('${arrayWorks[index].idCheck}')" id="${arrayWorks[index].idCheck}">
<label class="form-check-label" for="defaultCheck1" id="${arrayWorks[index].idLabel}">
${arrayWorks[index].textContent}
</label></input>
</li>`
}
}
}
const through = (idC) => {
arrayWorks[idC].status = true;
idC = parseInt(idC) + 1;
document.getElementById(idC).className += " incorrecto";
}
const addItem = () => {
let label = document.createElement("label");
label.textContent = document.getElementById("addText").value;
if (label.textContent === '') {
alert("Escribí algo!");
} else {
let work = {
idCheck: id,
idLabel: id + 1,
textContent: label.textContent,
status: false
}
arrayWorks.push(work);
let ul = document.getElementById("listWorks");
ul.innerHTML += `
<li><input class="Input" type="checkbox" onclick="through('${work.idCheck}')" id="${work.idCheck}">
<label class="form-check-label" for="defaultCheck1" id="${work.idLabel}">
${label.textContent}
</label></input>
</li>
`
console.log(arrayWorks)
id = id + 1;
refresh();
}
}