From c64f2ce09ba329650ab51a7a2f66454b979d9a77 Mon Sep 17 00:00:00 2001 From: Andrew Davidson Date: Mon, 29 Jan 2018 05:46:03 -0500 Subject: [PATCH] initial commit --- randomComment.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 randomComment.js diff --git a/randomComment.js b/randomComment.js new file mode 100644 index 0000000..b84e8d0 --- /dev/null +++ b/randomComment.js @@ -0,0 +1,21 @@ +var li = document.getElementsByTagName("li"); +console.log("Found ", li.length, " li tags"); +var comments = []; + +for (var l = 0; l < li.length - 1; l++) { + if (li[l].classList.contains("comment")) { + if (li[l].classList.contains("comment-author-bernie") == false) { + comments.push(li[l]); + } + } +} + +console.log("Found ", comments.length, " comments not by Bernie"); + +console.log("Choosing winner..."); +var winner = comments[Math.floor(Math.random() * comments.length)]; + +winner.querySelector("article").style.background = "gray"; +winner.scrollIntoViewIfNeeded(); + +// alert("The winner is: ", winnerName);