Simple question for this error

If I run this code it gives me an error saying lexical declaration cannot appear in a single-statement context.

I’m not sure specifically, but I do see some questionable syntax:

  while (Math.floor(num/10) > 0)
  //and repeat
  let currentCopy = num;
  while( currentCopy > 0){
    currentCopy = Math.floor(currentCopy / 10)
    let last_digit = num % 10;
    if (num % last_digit !== 0) {
      return false;

What is that first while loop doing? Since you haven’t wrapped what follows in a code block, it’s only going to loop the next line. I think you want a code block here.

const perfectNum = (number) => {
  let number = num;
  // ...

Why are you redeclaring number? A variable with that name is already being passed in.

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