Created
May 15, 2015 12:53
-
-
Save Terrycoco/26bfc82e6b91ca9ae42f to your computer and use it in GitHub Desktop.
Terry's Ping-Pong Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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