diff --git a/index.html b/index.html new file mode 100644 index 00000000..7029a4d0 --- /dev/null +++ b/index.html @@ -0,0 +1,58 @@ + + + + + + + + ReReddit + + + +
+
+
ReReddit
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ + + diff --git a/main.js b/main.js new file mode 100644 index 00000000..695cbab7 --- /dev/null +++ b/main.js @@ -0,0 +1,92 @@ +var posts = document.getElementById("posts") +var postList = document.getElementsByClassName('post'); +let postCount = 0; +var poster = document.getElementById("poster"); +var post = document.getElementById("post"); +const submitPost = document.getElementById("submitPost"); + + + +submitPost.addEventListener("click", function () { + if (post.value === '' && poster.value === '') { + alert('Oops! Looks like you hit submit by accident. Make sure you add your post text and name below.') + } else { + postCount++; + + + + posts.insertAdjacentHTML("beforeend", ` +
+ + + ${post.value} - Posted By: ${poster.value} +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
`); + + poster.value = ''; + post.value = ''; + + var comments = document.getElementById(`post${postCount}-comments`) + let commentCount = 0; + var commenter = document.getElementById(`post${postCount}-commenter`); + var comment = document.getElementById(`post${postCount}-comment`); + const submitComment = document.getElementById(`post${postCount}-submitComment`); + + submitComment.addEventListener("click", function () { + commentCount++; + + comments.insertAdjacentHTML("beforeend", ` +
+ + ${comment.value} - Posted By: ${commenter.value} +
`); + + comment.value = ''; + commenter.value = ''; + + const deleteBtns = Array.from(document.getElementsByClassName('delete')); + + deleteBtns.forEach(function (button) { + button.addEventListener('click', function () { + button.parentElement.remove(); + }); + }); + }); + + const deleteBtns = Array.from(document.getElementsByClassName('delete')); + + deleteBtns.forEach(function (button) { + button.addEventListener('click', function () { + button.parentElement.remove(); + }); + }); + }; +}); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 00000000..e69de29b