<p dir="auto">Challenge [Replacing If Else Chains with Switch](<a href="https://www.freecodecamp.com/challenges/replacing-if-else-chains-with-switch#?solution=%0Afunction%20chainToSwitch(val)%20%7B%0A%20%20var%20answer%20%3D%20%22%22%3B%0A%20%20%2F%2F%20Only%20change%20code%20below%20this%20line%0A%2F*%0A%20%20if%20(val%20%3D%3D%3D%20%22bob%22)%20%7B%0A%20%20%20%20answer%20%3D%20%22Marley%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%2042)%20%7B%0A%20%20%20%20answer%20%3D%20%22The%20Answer%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%201)%20%7B%0A%20%20%20%20answer%20%3D%20%22There%20is%20no%20%231%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%2099)%20%7B%0A%20%20%20%20answer%20%3D%20%22Missed%20me%20by%20this%20much!%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%207%20%7B%0A%20%20%20%20answer%20%3D%20%22Ate%20Nine%22%3B%0A%20%20%7D%0A%20%20*%2F%0A%20%20%0A%20%20switch%20(val)%20%7B%0A%20%20%20%20case%20%22bob%22%3A%0A%20%20%20%20%20%20answer%20%3D%20%22Marley%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%2042%3A%0A%20%20%20%20%20%20answer%20%3D%20%22The%20Answer%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%201%3A%0A%20%20%20%20%20%20answer%20%3D%20%22There%20is%20no%20%231%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%2099%3A%0A%20%20%20%20%20%20answer%20%3D%20%22Missed%20me%20by%20this%20much!%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%207%3A%0A%20%20%20%20%20%20answer%20%3D%20%22Ate%20Nine%22%3B%0A%20%20%20%20%20%20break%3B%20%20%20%20%20%20%0A%20%20%7D%0A%20%20%0A%20%20%2F%2F%20Only%20change%20code%20above%20this%20line%20%20%0A%20%20return%20answer%3B%20%20%0A%7D%0A%0A%2F%2F%20Change%20this%20value%20to%20test%0AchainToSwitch(7)%3B%0A%0A)" rel="nofollow">https://www.freecodecamp.com/challenges/replacing-if-else-chains-with-switch#?solution=%0Afunction%20chainToSwitch(val)%20%7B%0A%20%20var%20answer%20%3D%20%22%22%3B%0A%20%20%2F%2F%20Only%20change%20code%20below%20this%20line%0A%2F*%0A%20%20if%20(val%20%3D%3D%3D%20%22bob%22)%20%7B%0A%20%20%20%20answer%20%3D%20%22Marley%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%2042)%20%7B%0A%20%20%20%20answer%20%3D%20%22The%20Answer%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%201)%20%7B%0A%20%20%20%20answer%20%3D%20%22There%20is%20no%20%231%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%2099)%20%7B%0A%20%20%20%20answer%20%3D%20%22Missed%20me%20by%20this%20much!%22%3B%0A%20%20%7D%20else%20if%20(val%20%3D%3D%3D%207%20%7B%0A%20%20%20%20answer%20%3D%20%22Ate%20Nine%22%3B%0A%20%20%7D%0A%20%20*%2F%0A%20%20%0A%20%20switch%20(val)%20%7B%0A%20%20%20%20case%20%22bob%22%3A%0A%20%20%20%20%20%20answer%20%3D%20%22Marley%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%2042%3A%0A%20%20%20%20%20%20answer%20%3D%20%22The%20Answer%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%201%3A%0A%20%20%20%20%20%20answer%20%3D%20%22There%20is%20no%20%231%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%2099%3A%0A%20%20%20%20%20%20answer%20%3D%20%22Missed%20me%20by%20this%20much!%22%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20case%207%3A%0A%20%20%20%20%20%20answer%20%3D%20%22Ate%20Nine%22%3B%0A%20%20%20%20%20%20break%3B%20%20%20%20%20%20%0A%20%20%7D%0A%20%20%0A%20%20%2F%2F%20Only%20change%20code%20above%20this%20line%20%20%0A%20%20return%20answer%3B%20%20%0A%7D%0A%0A%2F%2F%20Change%20this%20value%20to%20test%0AchainToSwitch(7)%3B%0A%0A)</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/56.0.2924.87 Safari/537.36</code>.<br>
Please describe how to reproduce this issue, and include links to screenshots if possible.</p>
<p dir="auto">To reproduce, use the code in "my code" and then click Run tests. Notice that it is not passing the test because of the commented if/else statements.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/25354301/23678347/60d3797c-0349-11e7-8246-ae95c6e56eae.png"><img src="https://cloud.githubusercontent.com/assets/25354301/23678347/60d3797c-0349-11e7-8246-ae95c6e56eae.png" alt="2017-03-07 15_17_03-replacing if else chains with switch _ free code camp" style="max-width: 100%;"></a></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 chainToSwitch(val) {
  var answer = &quot;&quot;;
  // Only change code below this line
/*
  if (val === &quot;bob&quot;) {
    answer = &quot;Marley&quot;;
  } else if (val === 42) {
    answer = &quot;The Answer&quot;;
  } else if (val === 1) {
    answer = &quot;There is no #1&quot;;
  } else if (val === 99) {
    answer = &quot;Missed me by this much!&quot;;
  } else if (val === 7 {
    answer = &quot;Ate Nine&quot;;
  }
  */
  
  switch (val) {
    case &quot;bob&quot;:
      answer = &quot;Marley&quot;;
      break;
    case 42:
      answer = &quot;The Answer&quot;;
      break;
    case 1:
      answer = &quot;There is no #1&quot;;
      break;
    case 99:
      answer = &quot;Missed me by this much!&quot;;
      break;
    case 7:
      answer = &quot;Ate Nine&quot;;
      break;      
  }
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
chainToSwitch(7);

"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">chainToSwitch</span><span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">answer</span> <span class="pl-c1">=</span> <span class="pl-s">""</span><span class="pl-kos">;</span>
  <span class="pl-c">// Only change code below this line</span>
<span class="pl-c">/*</span>
<span class="pl-c">  if (val === "bob") {</span>
<span class="pl-c">    answer = "Marley";</span>
<span class="pl-c">  } else if (val === 42) {</span>
<span class="pl-c">    answer = "The Answer";</span>
<span class="pl-c">  } else if (val === 1) {</span>
<span class="pl-c">    answer = "There is no #1";</span>
<span class="pl-c">  } else if (val === 99) {</span>
<span class="pl-c">    answer = "Missed me by this much!";</span>
<span class="pl-c">  } else if (val === 7 {</span>
<span class="pl-c">    answer = "Ate Nine";</span>
<span class="pl-c">  }</span>
<span class="pl-c">  */</span>
  
  <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">case</span> <span class="pl-s">"bob"</span>:
      <span class="pl-s1">answer</span> <span class="pl-c1">=</span> <span class="pl-s">"Marley"</span><span class="pl-kos">;</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-c1">42</span>:
      <span class="pl-s1">answer</span> <span class="pl-c1">=</span> <span class="pl-s">"The Answer"</span><span class="pl-kos">;</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-c1">1</span>:
      <span class="pl-s1">answer</span> <span class="pl-c1">=</span> <span class="pl-s">"There is no #1"</span><span class="pl-kos">;</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-c1">99</span>:
      <span class="pl-s1">answer</span> <span class="pl-c1">=</span> <span class="pl-s">"Missed me by this much!"</span><span class="pl-kos">;</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-c1">7</span>:
      <span class="pl-s1">answer</span> <span class="pl-c1">=</span> <span class="pl-s">"Ate Nine"</span><span class="pl-kos">;</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>      
  <span class="pl-kos">}</span>
  
  <span class="pl-c">// Only change code above this line  </span>
  <span class="pl-k">return</span> <span class="pl-s1">answer</span><span class="pl-kos">;</span>  
<span class="pl-kos">}</span>

<span class="pl-c">// Change this value to test</span>
<span class="pl-en">chainToSwitch</span><span class="pl-kos">(</span><span class="pl-c1">7</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
</pre></div>
<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator#?solution=%0Afunction%20testLogicalAnd%28val%29%20%7B%0A%20%20%2F%2F%20Only%20change%20code%20below%20this%20line%0A%0A%20%20if%20%28val%3C%3D50%20%26%26%20val%3E%3D25%29%20%7B%0A%0A%20%20%20%20%20%20return%20%22Yes%22%3B%0A%2F%2F%20%20%20%20%20%0A%20%20%7D%0A%0A%20%20%2F%2F%20Only%20change%20code%20above%20this%20line%0A%20%20return%20%22No%22%3B%0A%7D%0A%0A%2F%2F%20Change%20this%20value%20to%20test%0AtestLogicalAnd%2810%29%3B%0A" rel="nofollow">Comparisons with the Logical And Operator</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 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="
function testLogicalAnd(val) {
  // Only change code below this line

  if (val&lt;=50 &amp;&amp; val&gt;=25) {

      return &quot;Yes&quot;;
//     
  }

  // Only change code above this line
  return &quot;No&quot;;
}

// Change this value to test
testLogicalAnd(10);
"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">testLogicalAnd</span><span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// Only change code below this line</span>

  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-c1">&lt;=</span><span class="pl-c1">50</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">val</span><span class="pl-c1">&gt;=</span><span class="pl-c1">25</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

      <span class="pl-k">return</span> <span class="pl-s">"Yes"</span><span class="pl-kos">;</span>
<span class="pl-c">//     </span>
  <span class="pl-kos">}</span>

  <span class="pl-c">// Only change code above this line</span>
  <span class="pl-k">return</span> <span class="pl-s">"No"</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c">// Change this value to test</span>
<span class="pl-en">testLogicalAnd</span><span class="pl-kos">(</span><span class="pl-c1">10</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>I commented out the second if statement and did not pass, this test failed 'You should only have one if statement'</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function testLogicalAnd(val) {
  // Only change code below this line

  if (val&lt;=50 &amp;&amp; val&gt;=25) {
//     if (val) {
      return &quot;Yes&quot;;
//     }
  }
  // Only change code above this line
  return &quot;No&quot;;
}
// Change this value to test
testLogicalAnd(10);"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">testLogicalAnd</span><span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// Only change code below this line</span>

  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-c1">&lt;=</span><span class="pl-c1">50</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">val</span><span class="pl-c1">&gt;=</span><span class="pl-c1">25</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-c">//     if (val) {</span>
      <span class="pl-k">return</span> <span class="pl-s">"Yes"</span><span class="pl-kos">;</span>
<span class="pl-c">//     }</span>
  <span class="pl-kos">}</span>
  <span class="pl-c">// Only change code above this line</span>
  <span class="pl-k">return</span> <span class="pl-s">"No"</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-c">// Change this value to test</span>
<span class="pl-en">testLogicalAnd</span><span class="pl-kos">(</span><span class="pl-c1">10</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Removing the if statement all together passed the test:</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function testLogicalAnd(val) {
  // Only change code below this line

  if (val&lt;=50 &amp;&amp; val&gt;=25) {

      return &quot;Yes&quot;;

  }
  // Only change code above this line
  return &quot;No&quot;;
}
// Change this value to test
testLogicalAnd(10);"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">testLogicalAnd</span><span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// Only change code below this line</span>

  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">val</span><span class="pl-c1">&lt;=</span><span class="pl-c1">50</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">val</span><span class="pl-c1">&gt;=</span><span class="pl-c1">25</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

      <span class="pl-k">return</span> <span class="pl-s">"Yes"</span><span class="pl-kos">;</span>

  <span class="pl-kos">}</span>
  <span class="pl-c">// Only change code above this line</span>
  <span class="pl-k">return</span> <span class="pl-s">"No"</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-c">// Change this value to test</span>
<span class="pl-en">testLogicalAnd</span><span class="pl-kos">(</span><span class="pl-c1">10</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Not sure if this is intended behavior but it felt like a bug, commenting out the second if statement would work under normal circumstances. Thanks.</p>
<p dir="auto">(Bouncey edited for code formatting)</p>