generated from imd1005-web-development-winter-2023/assignment-03-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
112 lines (76 loc) · 1.99 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// JS File
// Variables
var alltasks = [];
var checkbox = [];
//
// Functions
//
function delitetask(id) {
alltasks.splice(id, 1);
checkbox.splice(id, 1);
creatlistoftasks(alltasks);
}
function updatcheckbox(id) {
if (checkbox[id]) {
checkbox[id] = false;
}
else {
checkbox[id] = true;
}
}
function creatlistoftasks(list) {
var addNewList = document.getElementById("addNewList");
addNewList.innerHTML = "";
for (let i = 0; i < list.length; i++) {
var checked = checkbox[i] ? "checked" : "";
var newelement = "<li style='padding: 2.7%; border: 1px solid black; width: 50%; margin: 0 auto; background-color: cadetblue;'> <input type ='checkbox'" + checked + " onchange= 'updatcheckbox(" + i + ")'> " + alltasks[i] + "</input> <button id='" + i + "' onclick='delitetask(" + i + ")'> D-elete </button > </li > "; //newelement
addNewList.innerHTML += newelement;
}
}
function addtask() {
document.getElementById("AddNewTask").value;//value
var AddNewTask = document.getElementById("AddNewTask").value; //tack out value in input box
alltasks.push(AddNewTask);
creatlistoftasks(alltasks);
checkbox.push(false);
}
function clearAndRestart() {
alltasks = [];
checkbox = [];
creatlistoftasks(alltasks);
}
/*
// You may remove the code below - it's just boilerplate
//
//
// Variables
//
// Constants
const appID = "app";
const headingText = "To do. To done. ✅";
// Variables
// DOM Elements
let appContainer = document.getElementById(appID);
//
// Functions
//
// Add a heading to the app container
function inititialise() {
// If anything is wrong with the app container then end
if (!appContainer) {
console.error("Error: Could not find app contianer");
return;
}
// Create an h1 and add it to our app
const h1 = document.createElement("h1");
h1.innerText = headingText;
appContainer.appendChild(h1);
// Init complete
console.log("App successfully initialised");
}
//
// Inits & Event Listeners
//
inititialise();
*/