Created
December 19, 2015 18:02
-
-
Save fulgorek/d8bbf835d3b8199d58f6 to your computer and use it in GitHub Desktop.
Simple loop iteration with multiples
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
//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