Skip to content

Instantly share code, notes, and snippets.

@emilyboynton
Created April 18, 2016 20:41
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 emilyboynton/ce317e59b83551173caa31601b663ef1 to your computer and use it in GitHub Desktop.
Save emilyboynton/ce317e59b83551173caa31601b663ef1 to your computer and use it in GitHub Desktop.
CracklePop Program
/* cracklePop prints out numbers 1 - 100 while substituting "Crackle" and "Pop"
for numbers divisible by 3 and 5, respectively */
var cracklePop = function () {
/*print out the numbers 1 to 100 (inclusive). */
for (var i = 1; i <= 100; i++){
/* If the number is divisible by 3 and 5, print CracklePop */
if ( (i % 3 === 0) && (i % 5 === 0) ) {
console.log("CracklePop");
}
/* If the number is divisible by 3, print Crackle */
else if ( i % 3 === 0){
console.log("Crackle");
}
/* If the number is divisible by 5, print Pop */
else if ( i % 5 === 0) {
console.log("Pop");
}
/* Divisibility conditions not met: Print number */
else {
console.log(i);
}
}
};
cracklePop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment