Check if a Number is Prime in javaScript?
Create a function that outputs true if a number is prime, and false otherwise.
1 Answer
This function returns true if a number is prime, and false otherwise
function isPrime(num) {
for (i=2;i<Math.floor(Math.sqrt(num));i++){
if (num%i==0){return false}
}
return true
}
Example
isPrime(5) // true
isPrime(50) // false
answer Link