'Javascript Loop 3 - Test your skills' problem

Hi, I’m trying to do the 3rd Loop exercise from ‘test your skills’ section but I cannot find a bug in my code. I checked other posts here but it didn’t help to find it.

Thank you in advance.

My code:

let para = document.createElement(‘p’);
let i = 500;

function isPrime(num) {
  for(let i = 2; i < num; i++) {
    if(num % i === 0) {
      return false;
    }
  }

  return true;
}
do{
  if(isPrime(i)===true){
    para.textContent += i + ", ";
  }
  else{continue;
      }
  i--;
}
while(i>1);

let section = document.querySelector('section');
section.appendChild(para);

that’s the issue
cause in this code you go to the start of the do while without change the i value
just remove it and it will work fine

hope that help and have a nice day

1 Like