shockingu
03-18-2004, 08:55 PM
i am learning from a good book called javascript in easy steps.
and I am only on chapter 3. i thought that i could make a program that is for my friend and i have most of the knowlege on how to do it.
i am wanting my program to tell which numbers are prime or not so when i have entered them in a prompt then the code can tell the user if the number is prime or not. i have done some of the code but how i have done it i will need thousands of lines.
var num = prompt( "Type in a number to see if it is a prime number or not.", "");
if (num == 1)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
if (num == 3)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
if (num == 5)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
if (num == 2)
{
document.writeln("The number " + num + " is not a prime number." );
}
else
if (num == 4)
{
document.writeln("The number " + num + " is not a prime number." );
}
else
if (num == 6)
{
document.writeln("The number " + num + " is not a prime number." );
}
the above is some of the code that i have done but as you can see it will take thousands of lines.
i want the code so that it looks somthing like this
var num = prompt( "Type in a number to see if it is a prime number or not.", "");
if (num == 1,3,5,7,11,13)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
// even numbers
if (num == 2,4,6,8,10,12)
{
document.writeln("The number " + num + " is not a prime number." );
}
where the 1,3,5,7,11 prime numbers are the numbers that the code understands are prime and the code understands that the 2,4,6,8,10,12 is the non prime numbers.
i dont mind that i am going to get a big list of prime numbers like this 1, 3, 5, 7, 11, 13, 17, 19 but going all the way up to the number 100 in prime and a list of non primes going up to 100.
i want to know if this is posible to do it this way or if i would have to make thousands of lines of code. This is in a .js file.
and I am only on chapter 3. i thought that i could make a program that is for my friend and i have most of the knowlege on how to do it.
i am wanting my program to tell which numbers are prime or not so when i have entered them in a prompt then the code can tell the user if the number is prime or not. i have done some of the code but how i have done it i will need thousands of lines.
var num = prompt( "Type in a number to see if it is a prime number or not.", "");
if (num == 1)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
if (num == 3)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
if (num == 5)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
if (num == 2)
{
document.writeln("The number " + num + " is not a prime number." );
}
else
if (num == 4)
{
document.writeln("The number " + num + " is not a prime number." );
}
else
if (num == 6)
{
document.writeln("The number " + num + " is not a prime number." );
}
the above is some of the code that i have done but as you can see it will take thousands of lines.
i want the code so that it looks somthing like this
var num = prompt( "Type in a number to see if it is a prime number or not.", "");
if (num == 1,3,5,7,11,13)
{
document.writeln( "The number " + num + " is a prime number." );
}
else
// even numbers
if (num == 2,4,6,8,10,12)
{
document.writeln("The number " + num + " is not a prime number." );
}
where the 1,3,5,7,11 prime numbers are the numbers that the code understands are prime and the code understands that the 2,4,6,8,10,12 is the non prime numbers.
i dont mind that i am going to get a big list of prime numbers like this 1, 3, 5, 7, 11, 13, 17, 19 but going all the way up to the number 100 in prime and a list of non primes going up to 100.
i want to know if this is posible to do it this way or if i would have to make thousands of lines of code. This is in a .js file.