Skip to content

Instantly share code, notes, and snippets.

@AndrewThian
Created February 9, 2019 05:26
Show Gist options
  • Save AndrewThian/f5aa24414f18c1fbbcecced80a0412bf to your computer and use it in GitHub Desktop.
Save AndrewThian/f5aa24414f18c1fbbcecced80a0412bf to your computer and use it in GitHub Desktop.
js challenge print if number is prime.
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