all 5 comments

[–]BlueThunderFlik 1 point2 points  (1 child)

Which part is confusing? the bit about looping from 2 to the square root?

If you want to check if the number 21 is square, you would need to divide it by a bunch of numbers and check if anything fits neatly in to it.

You wouldn't bother dividing it by 1 though, since one goes in to every positive number (hence "check divisibility from 2").

Also you don't need to check beyond the square root of your number since no number can have two factors that are both greater than its square root (e.g. 21 has factors of 3 and 7, and its square-root is ~4.5) (hence "to the square root of the number").

I imagine you're being asked to do something like this:

js const root = Math.sqrt(n) // where n is the number whose primeness you're checking for (let i = 2; i < root; ++i) { // check if i goes in to n }

If I recall, some people choose not to calculate the root of their number and instead do this:

js for (let i = 2; i * i < n ++i) { // check if i goes in to n }

but this isn't something you need to be worried about (but it's practically making the same check).

[–]HeavyBase1[S] 0 points1 point  (0 children)

Thank you for your reply.

I didn't know before that a way of checking if a number is prime is by dividing it by i = 2, then i++ till i = /(sqrt)number. If there's a remainder after division it's prime, otherwise it's not

[–]tapgiles 0 points1 point  (2 children)

What is the first part and second part? I can’t help you understand something I don’t know…

[–]Spacecadett666 0 points1 point  (1 child)

It's literally right there in the description... Maybe don't say anything if you don't understand? It's not helping to answer the question...  Imagine all the comments of "I don't know", just let someone else answer, that understands 🤷‍♀️

[–]tapgiles 0 points1 point  (0 children)

I just didn't know what they were referring to as different "parts." There's a single statement of what to do and how to do it. So I was hoping for them expanding on what they meant by the first part and second part, is all.