Accepts number as input, writes the prime numbers up to that number to the screen.
Function to find prime numbers
function DisplayPrimeNumbers(number)
{
var this_number,divisor,not_prime;
this_number = 3;
while(this_number < number)
{
divisor = parseInt( this_number / 2);
not_prime = 0;
while(divisor > 1)
{
if(this_number % divisor == 0)
{
not_prime = 1;
divisor = 0;
}
else
{
divisor = divisor - 1;
}
}
if(not_prime == 0)
{
document.writeln(this_number + " is a prime number </br>");
}
this_number = this_number + 1;
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.