Quick actions

cmd+k|ctrl+k

Navigation

Languages

How to check a number is prime & How to find prime number within a spesific range 

Snippet info

Language

JavaScript

Visibility

public

Author

misbahul.munir0224

Created

2024-10-02T23:09:58.252779Z

Updated

2024-10-02T23:43:58.081037Z

function isPrime(n) {
    if(n < 2)  return false;
    for(let i = 2; i < n; i++){
    if(n%i==0){
      return false;  
    }
    }
    return true;
}
console.log(isPrime(9));
console.log(isPrime(10));
console.log(isPrime(11));
console.log(isPrime(4));
console.log(isPrime(5));
console.log(isPrime(6));
console.log(isPrime(7));
console.log(isPrime(8));
// function showPrimes(max) {
//     for(let i = 2; i <= max; i++){
//     if(isPrime(i)){
//         console.log(i)
//     }
// }
    
// }
// showPrimes(100);
INFO