Smallest Common Multiple - Getting "Unexpected Token ;" error

Smallest Common Multiple - Getting "Unexpected Token ;" error
0.0 0


I was working on the smallest common multiple. I thought I had figured it out and then I got an “Unexpected Token ;” error. I have put my code below and I have tried deleting all of the semi-colons one at a time (multiple times), but can’t figure out where the error is coming from.

function smallestCommons(arr) {
arr1 = [];
var y = 1;
  x = Math.min(arr[0],arr[1]);
  z = Math.max(arr[0],arr[1]);
  for(i=x; i<=z; i++) {
y = y*i;
  arr1.sort(function(a, b) {
return b - a;
  var test = 0;
  var increment = 1;

  do {
test = arr1[0] * increment * arr1[1];
for (i = 2; i < arr1.length; i++) {
  if (test % arr1[i] !== 0) {

  } while (i !== arr1.length);
  return i;



I’m not getting that error. I’m not getting the right answer, but I’m not getting an error and I am getting an answer.


This is weird. I’m getting a SyntaxError: missing while after do-loop body. I copied your code to and I didn’t get any weird error whatsoever.

Strangely enough, there’s no error when you remove the empty line before increment++ in that loop (or even just adding a space in that empty line).


One possible problem - you never declare arr1 with a var statement.