My new program

Recently, I made a program that detects prime numbers and non-prime numbers!

It’s very complicated!

Here it is!


function isPrime() {
   //all the variables
   var num = prompt("What is the number you seek?");
   var squarerooted = Math.sqrt(num); //defines the square root of num
   var primeTrue = false; // the true/false determiner
   var i = 2; //the first number to be divided into num
   var count = 0; //how many numbers below the square root of num divide evenly into num
   var Type = typeof num; //just a test
   console.log(Type); //just a test
   var finalOutput = "";
   //the test
   while (i<=squarerooted){
      if(num%i === 0){
   //determining the state of primeTrue : true or false?
   if(count === 0){primeTrue = true;}
   else{primeTrue = false;}
   //the final outputs
   if (primeTrue === true){console.log("PRIME"); finalOutput = "Prime";}
   else{console.log("NOT PRIME"); finalOutput = "Not prime";}
   console.log(finalOutput); // just a test
   document.getElementById("truefalse").innerHTML = finalOutput;


 <title>prime testing</title><style></style>
 <script>alert("1 is not prime, 0 is not prime, strings are not supposed to be prime.");</script>
 <button onclick="isPrime()">Try it</button>
 <p id="truefalse"></p>
 <script src="primetest.js"></script>


Copy and Paste these code pieces into two separate .txt files and save the Javascript as (your choice).js and the HTML as (your choice).html

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.