Skip to content

Instantly share code, notes, and snippets.

@fulgorek
Created December 19, 2015 18:02
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 fulgorek/d8bbf835d3b8199d58f6 to your computer and use it in GitHub Desktop.
Save fulgorek/d8bbf835d3b8199d58f6 to your computer and use it in GitHub Desktop.
Simple loop iteration with multiples
//Write a program that prints the numbers from 1 to 100. with the following conditions:
//For multiples of three [3] print “Hello” instead of the number.
//For the multiples of five [5] print “World” instead of the number.
//For numbers which are multiples of both three [3] and five[5] print “Hello World” instead of the number.
// we create a loop which iterate 100 times
for (i=0; i<100; i++){
if(i % 15 == 0){
// number is divisible by 3 and 5
console.log('Hello World')
} else if (i % 5 == 0) {
// number is divisible by 5 only
console.log('World')
} else if (i % 3 == 0) {
// number is divisible by 3 only
console.log('Hello')
} else {
console.log(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment