Skip to content

Added CS joke button and box #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added changes
  • Loading branch information
diyathangada committed Jan 21, 2022
commit 68ce470b9165df38712d9ea081b70fe2e2026e8f
9 changes: 7 additions & 2 deletions 010-dad jokes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ <h3>Don't Laugh Challenge</h3>
</div>
<script src="script.js"></script>
<br><br><br>
<div class="container">
<div id="container2" class="container">
<h3>Don't Laugh Challenge: Computer Science Edition</h3>
<div id="csJoke" class="joke">// Joke goes here</div>
<button class="btn" onclick="generateCSJoke();">Get Another Joke</button>
</div>
<script language="JavaScript">
Expand All @@ -25,11 +26,15 @@ <h3>Don't Laugh Challenge: Computer Science Edition</h3>
"Why couldn't the student use GitHub? They couldn't commit."];

function generateCSJoke(){
var removeJoke = document.getElementById("csJoke");
document.getElementById('container2').removeChild(removeJoke);
var i = parseInt(Math.random() * jokes.length);
const jokeDiv = document.createElement("div");
jokeDiv.setAttribute("id", "csJoke");
jokeDiv.setAttribute("class", "joke");
const jokeContent = document.createTextNode(jokes[i]);
jokeDiv.appendChild(jokeContent);
document.body.appendChild(jokeDiv);
document.getElementById('container2').appendChild(jokeDiv);
}
</script>
</body>
Expand Down