Skip to content

Instantly share code, notes, and snippets.

@pmutua
Created February 24, 2017 13:17
Show Gist options
  • Save pmutua/cc79dd87e29b33c5a8ce4b28662ef2d3 to your computer and use it in GitHub Desktop.
Save pmutua/cc79dd87e29b33c5a8ce4b28662ef2d3 to your computer and use it in GitHub Desktop.
jspingpong
//user
$(document).ready(function() {
$("form#pingPongForm").submit(function(event) {
$("#userOutput").empty();
var userInput = parseInt($("input#number").val());
var result = pingPongFun(userInput);
result.forEach(function(output) {
$("#userOutput").append("<li>" + output + "</li>");
event.preventDefault();
});
});
});
//business
function pingPongFun(userInput){
var result = [];
for (var i = 1; i <= userInput; i++){
if ((i % 15) === 0){
result.push ("Ping-Pong");
} else if ((i % 5) === 0){
result.push ("Pong");
} else if ((i % 3) === 0){
result.push ("Ping");
} else
result.push (i);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment