Created
April 18, 2016 20:41
-
-
Save emilyboynton/ce317e59b83551173caa31601b663ef1 to your computer and use it in GitHub Desktop.
CracklePop Program
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
/* 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