I am in the process of developing a code to identify prime numbers less than n. However, I encountered an issue where the code mistakenly flags 33 and 35 as prime numbers. I am puzzled by this unexpected outcome. Here is the code that I have been working on:
function primeFinder(n) {
let prime = []
let index = 0
for (let i = 2; i <= n; i++) {
let root = Math.floor(Math.sqrt(i))
for (let j = 2; j <= root; j++) {
if (i % j == 0) {
i++
break
}
}
prime[index] = i
index++
}
return (prime)
}
console.log(primeFinder(35))
Despite my efforts to accurately determine prime numbers, the code does not function as intended.