 # Making a code to check for primes numbers NOT WORKING

## This is the code Plz help fix

``````var prime=true
var isPrime=function(number) {
while(prime){
for(i=1,i<=number,i++){
if(number%i !== 0){
prime=false;
}
if(i===number){
prime=false;
}
}
}
}
isPrime(prompt("What number do you want to check primity for"))``````
1. Used a comma instead of semicolon in your for loop condition
2. Duplicated if statements, use else if or else.

Now, the problem with the function logic itself, is that relying on the modular won’t allways guarantee the number isn’t a prime. A non prime may go into an odd prime number.

``````5%2.5
0
``````

Here’s a quick idea about how I feel you would want to find out if a number is prime, without using an existing function. I would divide it incrementally until you get a 0.

``````function check(number) {
var store;
for(i=2; i<250; i++) {
store = number/i;
console.log(store);
}
}

check(234);``````

@emgo_dev Thanks I figured out how to do it and this is my new code

``````var checkPrime=function(number){
var prime=true
if(isNaN(number)>=true){
prime=false;
if(number===2) {
prime=false;
}

while(prime) {
for(var i=2;i<number;i++) {
}
if(number%i===0) {