how to count up to a specific number in javascript, fizzbuzz -
i'm trying solve problem similar popular fizzbuzz or pingpong question. figured out how write portion of code, need make counter in user inputs number , page gives 1 number input, fizzbuzz/popcorn numbers. think code along lines of
for (i = 1; <= 20; i++) {...}
but don't know how combine other code
var pingpong = function(number) { if (number % 15 === 0) { return 'pingpong'; } else if (number % 5 === 0) { return 'pong'; } else if (number % 3 === 0) { return 'ping'; } else { return false; } };
sorry, know super beginner question, i'm starting out , having hard time figuring out how works together.
you close. read more javascripts loops.
var pingpong = function(number) { if (number % 15 === 0) { return 'pingpong'; } else if (number % 5 === 0) { return 'pong'; } else if (number % 3 === 0) { return 'ping'; } else { return false; } }; (var = 1; <= 20; i++) { var num = pingpong(i); // show on screen document.body.innerhtml += + ': ' + num + '<br />'; }
Comments
Post a Comment