Loops 3. It's ok?

Hello teacher,
can you tell me if it’s ok. although it is defined, I used a for loop. as a result it is ok, but can you tell me if it is a correct approach?

for (let i = 500; i >= 2; i–) {
if(isPrime(i) === true){
para.textContent += i + “,”;
}else {
continue;
}
}

I would refactor it a bit:

for (let i = 500; i >= 2; i––) {
if (isPrime(i)) para.textContent += i + “,”;
}

I considered isPrime as a function that returns a boolean (true or false); I also corrected the first line that had the decrement sign with a single minus character (I think that’s what it was meant to be).

1 Like