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.
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.`);
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
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