Skip to content

Instantly share code, notes, and snippets.

@MineRobber9000
Created March 2, 2016 22:54
Show Gist options
  • Save MineRobber9000/e58783c2f4e74d01e75a to your computer and use it in GitHub Desktop.
Save MineRobber9000/e58783c2f4e74d01e75a to your computer and use it in GitHub Desktop.
Example for how to make a Button-Clicker style game.

(add this section to your readme.md)

Credits

MineRobber9000 - all of the "Button Clicker" style code.

var clicks = 0;
function goClick() {
var node = document.createElement("BUTTON");
var nodeText = document.createTextNode("CLICK ME");
node.appendChild(nodeText);
node.setAttribute("onclick", "goClick()");
document.body.appendChild(node);
clicks++;
document.getElementById("score").innerHTML = "<strong>" + clicks + "</strong>";
if (clicks > 99) {
document.getElementById("taunts").textContent = "Really?";
};
if (clicks > 199) {
document.getElementById("taunts").textContent = "Do you even excercise, bro?";
};
if (clicks > 499) {
document.getElementById("taunts").textContent = "Do you even have a life?";
};
if (clicks > 599) {
document.getElementById("taunts").textContent = "Do you even have a life? I'm being serious here.";
};
if (clicks > 999) {
document.getElementById("taunts").textContent = "Fine. You win. Go outside and get some excercise.";
};
if (clicks > 1099) {
document.getElementById("taunts").textContent = "You know what? I'm done.";
};
//any more taunts go here; use "if (clicks > number)"; e.x; "if (clicks > 1199)";
};
<html>
<head>
<title>Button Clicker Example - CHANGE TITLE!</title>
</head>
<body>
<h1>Title</h1>
<p>Description</p>
<p>You have <span id="score"><strong>0</strong></span></p>
<p id="taunts"></p><br>
<button onClick="goClick()">Begin!</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="buttonclicker.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment