Created
February 9, 2019 05:26
-
-
Save AndrewThian/f5aa24414f18c1fbbcecced80a0412bf to your computer and use it in GitHub Desktop.
js challenge print if number is prime.
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
function printPrime (num) { | |
for (let counter = 1; counter <= num; counter++) { | |
let prime = true; | |
for (let j = 2; j <= counter; j++) { | |
// if it can modus without remainder and it's not it self, means it's not prime | |
if (counter % j === 0 && counter !== j) { | |
prime = false; | |
} | |
} | |
if (prime) { | |
console.log(counter) | |
} | |
} | |
} | |
// printPrime(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment