# For 20- Exercise- Prime Numbers why can we not just do this

For this video why can we not just do this, I feel like mosh’s implementation is inefficient with 2 loops or am I wrong for hard coding the first primes would this be frowned upon in a job interview.
Mosh’s Implementation

``````showPrimes(20);
function showPrimes(limit){
for (let number = 2; number <= limit; number++){

let isPrime = true;
for (let factor = 2; factor < number; factor++){
if (number % factor === 0){
isPrime = false;
break;
}
}

if (isPrime) console.log(number);
}
}
``````

My Implementation

``````showPrimes(20);
function showPrimes(number){
if(number>=2) console.log(2)
if(number>=3) console.log(3)
if(number>=5) console.log(5)
if(number>=7) console.log(7)
for(let i = 8; i<=number; i++){
if((i%2!=0) && (i%3!=0) && (i%5!=0) && (i%7!=0))
console.log(i);
}
}
``````

Hi,

2 devs means likely 2 different solutions.

2 recruiters will have 2 different verdict on the same solution.

To answer the question.
There is nothing wrong with hardcoding the 1st values.

That said, I actually find Mosh solution more elegant.
The benefit you would get from hardcoding the 1st values is negligible IMHO.

Mosh is also teaching to beginners so it is not necessarily a good thing to make algorithms complex or advanced language feature wise.

Regards