Your code:
// Add your code here
for (let i = 500; i >= 2; i--) {
if (i !== isPrime(i)) {
const numArray = [i];
const primeNumber = numArray.filter(isPrime);
para.textContent += `${primeNumber} `;
}
}
function isPrime()
return true
or false
.
So, in your code you said like this if (i !== true/false)
it always evaluate to true
, i
is number.
You can simplify like this
if (isPrime(i)) {
para.textContent += `${i} `
}
You don’t need array in this test,
but if you want to stick with it.
for (let i = 500; i >= 2; i--) {
// remove if statement because is useless in here
const numArray = [i];
const primeNumber = numArray.filter(isPrime);
para.textContent += `${primeNumber} `;
}
But, don’t use that , you filter just 1 item in the array.