feat: add post comments
This commit is contained in:
parent
1bf1395ef6
commit
cd17ad53ad
18
main.js
18
main.js
|
@ -69,11 +69,27 @@ class Post {
|
||||||
|
|
||||||
postElem.appendChild(profileLinkElem);
|
postElem.appendChild(profileLinkElem);
|
||||||
|
|
||||||
// TODO: add content to the post
|
|
||||||
const contentElem = document.createElement("p");
|
const contentElem = document.createElement("p");
|
||||||
contentElem.innerHTML = this.content;
|
contentElem.innerHTML = this.content;
|
||||||
postElem.appendChild(contentElem);
|
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;
|
return postElem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue