programming-examples/js/Functions/Write a JavaScript function that accepts a number as a parameter and check the number is prime or not..js
2019-11-15 12:59:38 +01:00

24 lines
345 B
JavaScript

function test_prime(n)
{
if (n===1)
{
return false;
}
else if(n === 2)
{
return true;
}else
{
for(var x = 2; x < n; x++)
{
if(n % x === 0)
{
return false;
}
}
return true;
}
}
console.log(test_prime(37));