<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/smallest-common-multiple" rel="nofollow">Smallest Common Multiple</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.108 Safari/537.36</code>.<br>
Please describe how to reproduce this issue, and include links to screenshots if possible.</p>
<p dir="auto">My code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="//noprotect
function smallestCommons(arr) {
  for (var j=Math.max(...arr)+1;;){
    for (var i=2; i&lt;=Math.max(...arr);){
      if (j%i!==0) {j++; i=2; }
      else {i++;}
    }
    console.log(j);
    return j;
  }
}"><pre class="notranslate"><span class="pl-c">//noprotect</span>
<span class="pl-k">function</span> <span class="pl-en">smallestCommons</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">j</span><span class="pl-c1">=</span><span class="pl-v">Math</span><span class="pl-kos">.</span><span class="pl-en">max</span><span class="pl-kos">(</span>...<span class="pl-s1">arr</span><span class="pl-kos">)</span><span class="pl-c1">+</span><span class="pl-c1">1</span><span class="pl-kos">;</span><span class="pl-kos">;</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">i</span><span class="pl-c1">=</span><span class="pl-c1">2</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">&lt;=</span><span class="pl-v">Math</span><span class="pl-kos">.</span><span class="pl-en">max</span><span class="pl-kos">(</span>...<span class="pl-s1">arr</span><span class="pl-kos">)</span><span class="pl-kos">;</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
      <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">j</span><span class="pl-c1">%</span><span class="pl-s1">i</span><span class="pl-c1">!==</span><span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-s1">j</span><span class="pl-c1">++</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">=</span><span class="pl-c1">2</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>
      <span class="pl-k">else</span> <span class="pl-kos">{</span><span class="pl-s1">i</span><span class="pl-c1">++</span><span class="pl-kos">;</span><span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">j</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">j</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Without <code class="notranslate">//noprotect</code>, the loop breaks early.  I think this challenge should have a longer timeout, or at least a smaller test value than <code class="notranslate">13</code>.</p>
<p dir="auto">Challenge <a href="http://www.freecodecamp.com/challenges/smallest-common-multiple#?solution=%2F*%20This%20was%20a%20tough%20one%20for%20me.%0ALet's%20use%20the%20Euclidean%20Algorithm%20to%20first%20get%20the%20GCD%20and%20%0Athen%20use%20that%20to%20calculate%20the%20LCM%0AThis%20below%20function%20for%20obtaining%20the%20gcd%20was%20posted%20on%20StackOverflow%20by%20%22alex%22%20at%20%0Ahttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F17445231%2Fjs-how-to-find-the-greatest-common-divisor%2F17445304%2317445304.%20%0A*%2F%0Afunction%20gcd%28a%2C%20b%29%20%7B%0A%20%20%20%20if%20%28!b%29%20%7B%0A%20%20%20%20%20%20%20%20return%20a%3B%0A%20%20%20%20%7D%20%20%20%20%0A%20%20%20%20return%20gcd%28b%2C%20a%20%25%20b%29%3B%0A%7D%0A%0Afunction%20smallestCommons%28arr%29%20%7B%0A%20%20%20%20var%20newArr%20%3D%20%5B%5D%3B%20%2F*Will%20hold%20the%20range%20of%20numbers%20from%20arr%5B0%5D%20to%20arr%5B1%5D.*%2F%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20arr.sort%28function%28val1%2C%20val2%29%20%7B%20%2F*Order%20the%20array%20from%20least%20to%20greatest.*%2F%0A%20%20%20%20%20%20%20%20return%20val1%20-%20val2%3B%0A%20%20%20%20%7D%29%3B%0A%20%20%20%20%0A%20%20%20%20for%20%28var%20i%20%3D%20arr%5B0%5D%3B%20i%20%3C%3D%20arr%5B1%5D%3B%20i%2B%2B%29%20%7B%20%2F*Create%20the%20full%20range%20of%20values%20under%20consideration.*%2F%0A%20%20%20%20%20%20%20%20newArr.push%28i%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20%2F*Formula%20to%20use%20is%20LCM%28a%2Cb%29%20%3D%20a%20*%20b%20%2F%20GCD%28a%2C%20b%29.%20%0A%20%20%20%20Reduce%20array%20by%20recursively%20applying%20the%20formula%20to%20%0A%20%20%20%20the%20first%20two%20values%20until%20there%20is%20only%20one%20value%20left.*%2F%0A%20%20%20%20return%20newArr.reduce%28function%28a%2C%20b%29%20%7B%20%0A%20%20%20%20%20%20%20%20return%20%28a%20*%20b%29%20%2F%20%28gcd%28a%2C%20b%29%29%3B%0A%20%20%20%20%7D%29%3B%0A%7D%0A%0AsmallestCommons%28%5B1%2C%205%5D%29%3B%0A" rel="nofollow">Smallest Common Multiple</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36</code>.<br>
I keep receiving this error: "SyntaxError: Illegal break statement." That doesn't make any sense, because my code isn't using a break statement anywhere, even in my for loop. The code works and passes all test cases when I log the output in the console. Am I missing something?</p>
<p dir="auto">My code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/* This was a tough one for me.
Let's use the Euclidean Algorithm to first get the GCD and 
then use that to calculate the LCM
This below function for obtaining the gcd was posted on StackOverflow by &quot;alex&quot; at 
https://stackoverflow.com/questions/17445231/js-how-to-find-the-greatest-common-divisor/. 
*/
function gcd(a, b) {
    if (!b) {
        return a;
    }    
    return gcd(b, a % b);
}

function smallestCommons(arr) {
    var newArr = []; /*Will hold the range of numbers from arr[0] to arr[1].*/

    arr.sort(function(val1, val2) { /*Order the array from least to greatest.*/
        return val1 - val2;
    });

    for (var i = arr[0]; i &lt;= arr[1]; i++) { /*Create the full range of values under consideration.*/
        newArr.push(i);
    }

    /*Formula to use is LCM(a,b) = a * b / GCD(a, b). 
    Reduce array by recursively applying the formula to 
    the first two values until there is only one value left.*/
    return newArr.reduce(function(a, b) { 
        return (a * b) / (gcd(a, b));
    });
}

smallestCommons([1, 5]);
"><pre class="notranslate"><span class="pl-c">/* This was a tough one for me.</span>
<span class="pl-c">Let's use the Euclidean Algorithm to first get the GCD and </span>
<span class="pl-c">then use that to calculate the LCM</span>
<span class="pl-c">This below function for obtaining the gcd was posted on StackOverflow by "alex" at </span>
<span class="pl-c">https://stackoverflow.com/questions/17445231/js-how-to-find-the-greatest-common-divisor/. </span>
<span class="pl-c">*/</span>
<span class="pl-k">function</span> <span class="pl-en">gcd</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">,</span> <span class="pl-s1">b</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">b</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-s1">a</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>    
    <span class="pl-k">return</span> <span class="pl-en">gcd</span><span class="pl-kos">(</span><span class="pl-s1">b</span><span class="pl-kos">,</span> <span class="pl-s1">a</span> <span class="pl-c1">%</span> <span class="pl-s1">b</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">smallestCommons</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">newArr</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span> <span class="pl-c">/*Will hold the range of numbers from arr[0] to arr[1].*/</span>

    <span class="pl-s1">arr</span><span class="pl-kos">.</span><span class="pl-en">sort</span><span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">val1</span><span class="pl-kos">,</span> <span class="pl-s1">val2</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">/*Order the array from least to greatest.*/</span>
        <span class="pl-k">return</span> <span class="pl-s1">val1</span> <span class="pl-c1">-</span> <span class="pl-s1">val2</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;=</span> <span class="pl-s1">arr</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">++</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">/*Create the full range of values under consideration.*/</span>
        <span class="pl-s1">newArr</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s1">i</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-c">/*Formula to use is LCM(a,b) = a * b / GCD(a, b). </span>
<span class="pl-c">    Reduce array by recursively applying the formula to </span>
<span class="pl-c">    the first two values until there is only one value left.*/</span>
    <span class="pl-k">return</span> <span class="pl-s1">newArr</span><span class="pl-kos">.</span><span class="pl-en">reduce</span><span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">,</span> <span class="pl-s1">b</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> 
        <span class="pl-k">return</span> <span class="pl-kos">(</span><span class="pl-s1">a</span> <span class="pl-c1">*</span> <span class="pl-s1">b</span><span class="pl-kos">)</span> <span class="pl-c1">/</span> <span class="pl-kos">(</span><span class="pl-en">gcd</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">,</span> <span class="pl-s1">b</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">smallestCommons</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">5</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>