números primos javascript
function isPrime(num) {
for (let i = 2; i * i <= num; i++)
if (num % i === 0)
return false;
return num > 1;
}
TC5550
function isPrime(num) {
for (let i = 2; i * i <= num; i++)
if (num % i === 0)
return false;
return num > 1;
}
// range = 1 o 20
for(let number=2 ; number<=20; number++){
let isPrime = true;
for (let i=2; i<= number-1;i++){
if(number%i===0){
isPrime = false;
break
}
}
if (isPrime) console.log(number);
}
// result = 2,3,5,7,11,13,17,19
function identifyPrime(num) {
let count=0
for(i=2;i<=num;i++){
if(num%i===0){
count=count+1
}
}
if (count<2){
console.log("Yes")
}
else{
console.log("No")
}
}