For loops to test an prime number

Please, I need some help to solve this problem!

Challenge is:

What should be the expressions in the instruction below to test whether a given number is prime (divisible only by 1 and itself) or not?

In the code image, you can see the space where I can make changes to better understand the challenge. I can only make changes in the [initialization]; [condition] as you see in the example on the attached image.

beneath you can see my tried code

let n = 17; // the commands below can work for any values of n

let prime = true;
for(let i = 1; i > n; i--) 
   if(n%i == 0) // Tests whether n is divisible by i
     prime = false;
console.log(`${n} ${!prime?"no ":""} is a prime number.`);

Why start with 1?

Note - its best to use {} with your loops and if statements

hi ! so I have tried many ways but none of them print to me the correct answer.
So the first try was for ( let i = 0 ; i > n ; i–) and it did not work.
That was my last try.

however the answer has to print prime and non-prime numbers when I change the variable N

Can you answer this question please?

I’m very sorry Jeremy, there is a missing digit I intended to write 19. Because I thought as the condition in the expression is i > ; to create a variable i as value of 19 could run the code to tell me if the variable N=17 is a prime number or not !

I’m a very beginner learner. I am sorry about printing the screen of the challenge with that mistake

thanks very much for your tried to help.
Discussing that problem with my wife she got the way to figure it out.
for (let i = n - 1; i > 1; i–)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.