Skip to content

Instantly share code, notes, and snippets.

@Terrycoco
Created May 15, 2015 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Terrycoco/26bfc82e6b91ca9ae42f to your computer and use it in GitHub Desktop.
Save Terrycoco/26bfc82e6b91ca9ae42f to your computer and use it in GitHub Desktop.
Terry's Ping-Pong Test
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Ping Pong!</title>
</head>
<body>
<h1>Terry's Ping Pong!</h1>
<div id="myDiv"></div>
<script>
function pingPong() {
var num = prompt("How many volleys would you like?", "25");
var div = document.getElementById("myDiv");
var html = "";
if (typeof num != "undefined" && !isNaN(num) ) {
for (var i = 1; i <= num; i++) {
var li = "";
if (i % 3 == 0) {
li = "ping";
}
if (i % 5 == 0) {
li += (li ? "-pong" : "pong");
}
html += ("<li>" + (li || i) + "</li>")
}
div.innerHTML = html;
} else {
div.innerHTML = "<p>Oops. You didn't enter a number!</p>";
}
}
window.onload = pingPong;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment