Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created January 12, 2016 22:12
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 jrmoran/3c12ad2ebf3033f611a6 to your computer and use it in GitHub Desktop.
Save jrmoran/3c12ad2ebf3033f611a6 to your computer and use it in GitHub Desktop.
/*
* Write a program that prints out the numbers 1 to 100 (inclusive).
* If the number is divisible by 3, print Crackle instead of the number.
* If it's divisible by 5, print Pop. If it's divisible by both 3 and 5,
* print CracklePop
*
* Jaime Moran
*/
var cracklePop = function(i){
var r = '';
if(i % 3 === 0) r += 'Crackle';
if(i % 5 === 0) r +='Pop';
return r;
};
for(var i=1; i<=100; i++){
var str = cracklePop(i);
if(str !== ''){
console.log(i + ": " + str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment