From cd17ad53ad80cbb1e654e075ab813a6bbee178b1 Mon Sep 17 00:00:00 2001 From: ktyl Date: Sat, 13 Jul 2024 01:45:55 +0100 Subject: [PATCH] feat: add post comments --- main.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 6514297..de37d36 100644 --- a/main.js +++ b/main.js @@ -69,11 +69,27 @@ class Post { postElem.appendChild(profileLinkElem); - // TODO: add content to the post const contentElem = document.createElement("p"); contentElem.innerHTML = this.content; postElem.appendChild(contentElem); + // add a random number of comments to the post + const numComments = Math.random() * 5; + for (let i = 0; i < numComments; i++) { + const commentElem = document.createElement("div"); + commentElem.style.backgroundColor = getRandomColor(); + + const commentUserElem = document.createElement("h2"); + commentUserElem.innerHTML = getUsername(); + commentElem.appendChild(commentUserElem); + + const commentContentElem = document.createElement("p"); + commentContentElem.innerHTML = `comment ${i}`; + commentElem.appendChild(commentContentElem); + + postElem.appendChild(commentElem); + } + return postElem; } }