-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
40 lines (34 loc) · 1.42 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
let jsonObj = '["This is message number one!", "This is another message!", "I love cats!", ' +
'"Could probably die for them", "How do people come up with messages...?", ' +
'"Just trying to fill the page do not mind me...", "what happens if I add one more?"]';
let msgList = JSON.parse(jsonObj);
function drawList() {
for (const msg of msgList) {
let newMsgBox = document.createElement("div"); // Create a <button> element
newMsgBox.innerHTML = msg;
newMsgBox.id = msg;
newMsgBox.classList.add("msg"); // add css class for position/style// add onclick functionality
document.getElementById("topPanel").appendChild(newMsgBox);
}
}
function clearList() {
const topPanel = document.getElementById("topPanel");
for (const msg of msgList) {
if (document.getElementById(msg)) {
topPanel.removeChild(document.getElementById(msg));
}
}
msgList = [];
}
function addMsg() {
let newMsg = document.getElementById("mainText").value;
msgList.push(newMsg);
let newMsgBox = document.createElement("div"); // Create a <button> element
newMsgBox.innerHTML = newMsg;
newMsgBox.id = newMsg;
newMsgBox.classList.add("msg"); // add css class for position/style// add onclick functionality
document.getElementById("topPanel").appendChild(newMsgBox);
}
function eraseText() {
document.getElementById("mainText").value = "";
}