Jump to content

Won't work, no idea why


Wilshire

Recommended Posts

This isn't working for me at all, nothing shows up:

<html><body><script type="text/javascript">var A=Number(prompt("Number:"));var B=Number(1);While (B<Math.pow(A,.5)){B++if (A%B==0){break}}if (B<Math.pow(A,.5)){document.write(A+" is a prime number.")}else{document.write(A+" is not a prime number.")}</script></body></html>

Link to comment
Share on other sites

give this a try

<html><head>	<title>...</title></head><body><script type="text/javascript">	var A = parseFloat(prompt("Number:"));	var B = parseInt(1);	while (B<Math.pow(A,.5))	{		if (A%B == 0){document.write("nothing left.")}		if (B<Math.pow(A,.5))			document.write(A+" is a prime number.")		else			document.write(A+" is not a prime number.")		B++	}</script></body></html>

Link to comment
Share on other sites

That didn't work, but it certainally helped. Final version:

<html><body><script type="text/javascript">var A = Number(prompt("Number:"));var B = Number(2);while (B<A){if (A%B == 0){break}B++;}if (B<A){document.write(A+" is not a prime number.")}else{document.write(A+" is a prime number.")}</script></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...