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

**URL:** <https://forum.codewithmosh.com/t/for-20-exercise-prime-numbers-why-can-we-not-just-do-this/21336>\
**Category:** JavaScript\
**Created:** [July 8, 2023, 2:09pm UTC](https://forum.codewithmosh.com/t/for-20-exercise-prime-numbers-why-can-we-not-just-do-this/21336 "2023-07-08T14:09:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nafislord](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/nafislord/32/6616_2.png) [@Nafislord](https://forum.codewithmosh.com/u/Nafislord)\
**Post date:** [July 8, 2023, 2:09pm UTC](https://forum.codewithmosh.com/t/for-20-exercise-prime-numbers-why-can-we-not-just-do-this/21336/1 "2023-07-08T14:09:21Z")

</div>

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);
    }
}

```

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [July 8, 2023, 7:11pm UTC](https://forum.codewithmosh.com/t/for-20-exercise-prime-numbers-why-can-we-not-just-do-this/21336/2 "2023-07-08T19:11:08Z")

</div>

Hi,

> [@Nafislord](#):
>
> would this be frowned upon in a job interview

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
