r/JavaScriptTips • • May 13 '22

Function help

Post image
4 Upvotes

4 comments sorted by

View all comments

2

u/AcanthocephalaDue494 May 13 '22

In the above function I’m trying to find the prime numbers between 2 and the entered number n. When I carry out this function I always just end up with 2 in my array. Am I missing something? It’s like it hits two then the loop ends

6

u/pzoxicuvybtnrme May 13 '22

Return numbers needs to be outside the for loop otherwise it's being called after one iteration and ends the loop

4

u/AcanthocephalaDue494 May 13 '22

Wow that’s crazy, it’s really the smallest things sometimes. Thank you!