<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/sum-all-odd-fibonacci-numbers#?solution=function%20sumFibs%28num%29%20%7B%0A%20%20var%20prevNum%20%3D%201%3B%0A%20%20var%20curNum%20%3D%201%3B%0A%20%20var%20result%20%3D%202%3B%0A%0A%20%20do%20%7B%0A%20%20%20%20var%20newNum%20%3D%20prevNum%20%2B%20curNum%3B%0A%0A%20%20%20%20if%20%28newNum%20%25%202%20!%3D%3D%200%20%26%26%20newNum%20%3C%3D%20num%29%20%7B%0A%20%20%20%20%20%20result%20%2B%3D%20newNum%3B%0A%20%20%20%20%7D%0A%20%20%20%20prevNum%20%3D%20curNum%3B%0A%20%20%20%20curNum%20%3D%20newNum%3B%0A%20%20%7D%20while%20%28curNum%20%3C%20num%29%3B%0A%0A%20%20console.log%28result%29%3B%0A%20%20return%20result%3B%0A%7D%0A%0AsumFibs%281000%29%3B" rel="nofollow">Sum All Odd Fibonacci Numbers</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36</code>.<br>
Please describe how to reproduce this issue, and include links to screenshots if possible.</p>
<p dir="auto">The issue I am having is with receiving a "SyntaxError: Unexpected token ;" syntax error. This issue has to do with the semicolon at the end of the do while, which is syntactically correct. This prevents the code from running. While there is a work around, I just wanted to shed some light.</p>
<p dir="auto">Thanks</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="function sumFibs(num) {
  var prevNum = 1;
  var curNum = 1;
  var result = 2;

  do {
    var newNum = prevNum + curNum;

    if (newNum % 2 !== 0 &amp;&amp; newNum &lt;= num) {
      result += newNum;
    }
    prevNum = curNum;
    curNum = newNum;
  } while (curNum &lt; num);

  console.log(result);
  return result;
}

sumFibs(1000);"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">sumFibs</span><span class="pl-kos">(</span><span class="pl-s1">num</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">prevNum</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">curNum</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span><span class="pl-kos">;</span>

  <span class="pl-k">do</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">newNum</span> <span class="pl-c1">=</span> <span class="pl-s1">prevNum</span> <span class="pl-c1">+</span> <span class="pl-s1">curNum</span><span class="pl-kos">;</span>

    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">newNum</span> <span class="pl-c1">%</span> <span class="pl-c1">2</span> <span class="pl-c1">!==</span> <span class="pl-c1">0</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">newNum</span> <span class="pl-c1">&lt;=</span> <span class="pl-s1">num</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-s1">result</span> <span class="pl-c1">+=</span> <span class="pl-s1">newNum</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-s1">prevNum</span> <span class="pl-c1">=</span> <span class="pl-s1">curNum</span><span class="pl-kos">;</span>
    <span class="pl-s1">curNum</span> <span class="pl-c1">=</span> <span class="pl-s1">newNum</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span> <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-s1">curNum</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">num</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">result</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">return</span> <span class="pl-s1">result</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">sumFibs</span><span class="pl-kos">(</span><span class="pl-c1">1000</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">my comment</h2>
<p dir="auto">the code runs with node, e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="node test.js"><pre class="notranslate"><code class="notranslate">node test.js
</code></pre></div>
<p dir="auto">in FCC it doesn't work.<br>
I'm using two while loops (outer and inner) what might be the cause.</p>
<h2 dir="auto">auto generated text</h2>
<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/sorted-union#?solution=%0Afunction%20mergeArrays(x)%20%7B%0A%20%20%2F%2F%20empty%20array%20as%20initial%20value.%20Combine%20two%20arrays%20several%20times.%0A%20%20return%20x.reduce(function(a%2Cb)%7Breturn%20a.concat(b)%3B%7D%2C%5B%5D)%3B%0A%7D%0A%0Afunction%20uniteUnique()%7B%0A%20%20%2F%2F%20convert%20JSON%20(the%20arguments%20variable)%20to%20an%20Array%0A%20%20var%20arr%20%3D%20%5B%5D.slice.call(arguments)%3B%20%2F%2Fconsole.log(arr)%3B%0A%20%20%2F%2F%20merge%20initially%0A%20%20arr%20%3D%20mergeArrays(arr)%3B%0A%20%20%2F%2F%20start%20outer%20while%20loop%0A%20%20var%20flag%20%3D%20true%3B%0A%20%20while(flag)%7B%0A%20%20%20%20%2F%2F%20check%20if%20one%20element%20is%20an%20array%0A%20%20%20%20var%20stopped%3Dfalse%3B%0A%20%20%20%20var%20i%3D0%3B%0A%20%20%20%20while(i%3Carr.length%20%26%26%20!stopped)%7B%0A%20%20%20%20%20%20%2F%2F%20stop%20if%20one%20element%20is%20an%20Array%0A%20%20%20%20%20%20if(Array.isArray(arr%5Bi%5D))%7Bstopped%3Dtrue%3B%7D%0A%20%20%20%20%20%20i%2B%2B%3B%0A%20%20%20%20%7D%0A%20%20%20%20if(stopped)%7B%0A%20%20%20%20%20%20%2F%2F%20merge%20elements%20that%20are%20numbers%2Fstrings%20and%20Arrays.%0A%20%20%20%20%20%20arr%20%3D%20mergeArrays(arr)%3B%0A%20%20%20%20%7Delse%7B%0A%20%20%20%20%20%20%2F%2F%20abort%20outer%20while%20loop%0A%20%20%20%20%20%20flag%20%3D%20false%3B%0A%20%20%20%20%7D%0A%20%20%20%20%2F%2Fconsole.log(arr)%3B%0A%20%20%7D%0A%20%20return%20arr%3B%0A%7D%0A%0A%0Aconsole.log(uniteUnique(%5B1%2C%203%2C%202%5D%2C%20%5B5%2C%202%2C%201%2C%204%5D%2C%20%5B2%2C%201%5D))%3B%0Aconsole.log(uniteUnique(%5B1%2C%203%2C%202%5D%2C%20%5B1%2C%20%5B5%5D%5D%2C%20%5B2%2C%20%5B4%5D%5D))%3B%0Aconsole.log(uniteUnique(%5B1%2C%202%2C%203%5D%2C%20%5B5%2C%202%2C%201%5D))%3B%0Aconsole.log(uniteUnique(%5B1%2C%202%2C%203%5D%2C%20%5B5%2C%202%2C%201%2C%204%5D%2C%20%5B2%2C%201%5D%2C%20%5B6%2C%207%2C%208%5D))%3B%0Aconsole.log(uniteUnique(%5B1%2C%203%2C%202%5D%2C%20%5B3%2C%20%5B1%2C%20%5B5%5D%5D%5D%2C%20%5B2%2C%20%5B4%5D%5D))%3B%0A" rel="nofollow">Sorted Union</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14</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="
function mergeArrays(x) {
  // empty array as initial value. Combine two arrays several times.
  return x.reduce(function(a,b){return a.concat(b);},[]);
}

function uniteUnique(){
  // convert JSON (the arguments variable) to an Array
  var arr = [].slice.call(arguments); //console.log(arr);
  // merge initially
  arr = mergeArrays(arr);
  // start outer while loop
  var flag = true;
  while(flag){
    // check if one element is an array
    var stopped=false;
    var i=0;
    while(i&lt;arr.length &amp;&amp; !stopped){
      // stop if one element is an Array
      if(Array.isArray(arr[i])){stopped=true;}
      i++;
    }
    if(stopped){
      // merge elements that are numbers/strings and Arrays.
      arr = mergeArrays(arr);
    }else{
      // abort outer while loop
      flag = false;
    }
    //console.log(arr);
  }
  return arr;
}


console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]));
console.log(uniteUnique([1, 3, 2], [1, [5]], [2, [4]]));
console.log(uniteUnique([1, 2, 3], [5, 2, 1]));
console.log(uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]));
console.log(uniteUnique([1, 3, 2], [3, [1, [5]]], [2, [4]]));
"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">mergeArrays</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// empty array as initial value. Combine two arrays several times.</span>
  <span class="pl-k">return</span> <span class="pl-s1">x</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-s1">a</span><span class="pl-kos">.</span><span class="pl-en">concat</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-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">uniteUnique</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
  <span class="pl-c">// convert JSON (the arguments variable) to an Array</span>
  <span class="pl-k">var</span> <span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">slice</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-smi">arguments</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">//console.log(arr);</span>
  <span class="pl-c">// merge initially</span>
  <span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-en">mergeArrays</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-c">// start outer while loop</span>
  <span class="pl-k">var</span> <span class="pl-s1">flag</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
  <span class="pl-k">while</span><span class="pl-kos">(</span><span class="pl-s1">flag</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-c">// check if one element is an array</span>
    <span class="pl-k">var</span> <span class="pl-s1">stopped</span><span class="pl-c1">=</span><span class="pl-c1">false</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">0</span><span class="pl-kos">;</span>
    <span class="pl-k">while</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">length</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-c1">!</span><span class="pl-s1">stopped</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
      <span class="pl-c">// stop if one element is an Array</span>
      <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-v">Array</span><span class="pl-kos">.</span><span class="pl-en">isArray</span><span class="pl-kos">(</span><span class="pl-s1">arr</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-kos">{</span><span class="pl-s1">stopped</span><span class="pl-c1">=</span><span class="pl-c1">true</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-k">if</span><span class="pl-kos">(</span><span class="pl-s1">stopped</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
      <span class="pl-c">// merge elements that are numbers/strings and Arrays.</span>
      <span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-en">mergeArrays</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-k">else</span><span class="pl-kos">{</span>
      <span class="pl-c">// abort outer while loop</span>
      <span class="pl-s1">flag</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-c">//console.log(arr);</span>
  <span class="pl-kos">}</span>
  <span class="pl-k">return</span> <span class="pl-s1">arr</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-en">uniteUnique</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">3</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">5</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">4</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">2</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-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-en">uniteUnique</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">3</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</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-kos">[</span><span class="pl-c1">5</span><span class="pl-kos">]</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">4</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-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-en">uniteUnique</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">2</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">5</span><span class="pl-kos">,</span> <span class="pl-c1">2</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-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-en">uniteUnique</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">2</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">5</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">4</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">2</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-kos">[</span><span class="pl-c1">6</span><span class="pl-kos">,</span> <span class="pl-c1">7</span><span class="pl-kos">,</span> <span class="pl-c1">8</span><span class="pl-kos">]</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-en">uniteUnique</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">3</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">3</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-kos">[</span><span class="pl-c1">5</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-c1">2</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">4</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></pre></div>