Smallest Common Multiple - Do/While error

Smallest Common Multiple - Do/While error
0

#1

Hello,

i have the code that i tested on codepen and it runs but on FCC it returns me the error:
Syntax Error: missing while after do-loop body
but i checked the while and it semms to be all ok.

This is the while loop:

     do {
    quot = newArr[0] * loop * newArr[1];
    for (n = 2; n < newArr.length; n++) {
      if (quot % newArr[n] !== 0) {
        break;
      }
    }

    loop++;
  } while (n !== newArr.length);

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

It looks like you’ve only shared part of your solution. Can you please edit this post to have your complete solution or a link to your code?


#3
function smallestCommons(arr) {
  
  arr.sort(function(a, b) {
return b - a;
  });

  
  var newArr = [];
  for (var i = arr[0]; i >= arr[1]; i--) {
newArr.push(i);
  }

  
  var quot = 0;
  var loop = 1;
  var n;

  
  do {
quot = newArr[0] * loop * newArr[1];
for (n = 2; n < newArr.length; n++) {
  if (quot % newArr[n] !== 0) {
    break;
  }
}

loop++;
  } while (n !== newArr.length);

  return quot;
}

#4

Looks like a bug in codemirror (the in-browser editor that FCC uses) maybe? If I remove the semicolon after while (n !== newArr.length) it shows a syntax error in the editor, but the challenge passes. With the semicolon there, the tests fail on a syntax error.


#5

Now it works.
Thank you!