title: Jumping on the Clouds HackerRank
body: <p><a href="https://i.stack.imgur.com/6otmw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6otmw.png" alt="enter image description here"></a>I want to make a function to return an array with the number of steps it will take to finish another array but with a little condition that i want to take my steps on 0 only and that mean if i have array c = [0,0,0,1,0,0,1,0] it will take the first three 0 as one step but if i have just one 0 as you see in the end of the array it will be a step so for this array it will take 4 steps to finish it (0,0,0)(0)(0)(0) as you see it will ignore (1)</p>
  
  <p>This is the link of the test if you want better description 
  <a href="https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem?filter=javascript&amp;filter_on=language&amp;h_l=interview&amp;h_r=next-challenge&amp;h_r=next-challenge&amp;h_v=zen&amp;h_v=zen&amp;page=1&amp;playlist_slugs%5B%5D=interview-preparation-kit&amp;playlist_slugs%5B%5D=warmup" rel="nofollow noreferrer">HakerRank tets link</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var array = [0, 0, 0, 1, 0, 0, 1, 0]
  var stepsArray = [];
  
  function jumpingOnClouds(c) {
    for (var i = 0; i &lt; c.length; i++) {
      if (c[i] === 0) {
        if (c[i] === c[i + 1])
          stepsArray.push(c[i + 1])
      } else {
        stepsArray.push(c[i])
      }
    }
  
    return stepsArray.length
  
  }
  var result = jumpingOnClouds(array);
  console.log(result);</code></pre>
  </div>
  </div>
  </p>
  
  <p>I also have tried this but it keep giving me the same error</p>
  
  <pre><code>   var array = [0, 0, 0, 1, 0, 0]
     var stepsArray = [];
     function jumpingOnClouds(c) {
      for(var i = 0; i &lt; c.length - 1; i++){
          if (c[i] === 0) {
              console.log(c[i])
              if (c[i] === c[i + 1] &amp;&amp; c[i + 1] === c[i + 2]) {
                  stepsArray.push(c[i + 2])
              } else if (c[i] === c[i + 1]) {
                  stepsArray.push(c[i + 1])
              } else {
                  stepsArray.push(c[i])
              }
          }
      }
      return stepsArray.length
  
  }
  var result = jumpingOnClouds(array);
  console.log(result)
  </code></pre>