Anyone know why this wont work?
Just learning Javascript and thought I would make some formula to work out which numbers are prime for those under 100.
The script is fine and works seperately, so you can ignore that to an extent, but when added into a function called myfunction it won't work.
Using an input button (not sure if thats the way it should be done but it'll do).
Here's the header code:
<script type="text/javascript">
function myfunction()
{
var a, b, c, d;
for (num=1; num<=100; num++)
{
// Creating variables that hold the remainder when num is divided by these 5 numbers
a=num%2; b=num%3; c=num%5; d=num%7;
// If the number is 2, 3, 5 or 7 write it now
if (num==2 || num==3 || num==5 || num==7)
{
document.write(num + ", ");
}
// If the remainders of all aren't 0 or if the number isn't 1 then write it out as a prime
else if (a!=0 && b!=0 && c!=0 && d!=0 && num!=1)
{
document.write(num + ", ");
}
}
}
</script>
and the body:
<input type="button" value="Yeah!" onclick="myfunction()" />