Sum All Odd Fibonacci Numbers (Can anybody just explain what is happening in while loop and why we used while loop?

Tell us what’s happening:

Your code so far

[The question is about the Basic Code Solution from the guide article on this challenge here]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.

Link to the challenge:

The while loop runs whilst the current number is less than or equal to the number specified, so it will run until you reach the argument passed to the function.

As we only want to sum all odd numbers, the if statement determines whether the modulus (remainder) of the current number divided by 2 is 0 (identifying it as an even number). If the remainder is not 0, the number is odd and is added to the result:

The application then moves onto the next number to test to continue the loop until it has checked all values:

Please don’t post the code from the guide, we are trying to reduce the number of full-working solutions. If you hahve questions about a guide solution please post the link to the guide and explain which of the solutions you are talking about and what is your question

the guide does not have any other working code so here is another simple hair splitter that uses for loop :wink: hope this will help better visualization of the Fibonacci process:

  function sumFibs(num) {
  var i,ii,iii=2,y=1;
    for (i=0;i<=num; ){
      i<3 ? ii=1  : ii=iii;
      i%2===0? "" : y=y+i ;
      iii=i;    //forward reference to be used by ii
      i=i+ii;   //incrementing i to loop
    }
    return y;
  }
  sumFibs(10);
==================
the solution had to be visualized using this mockup pattern:
where  1, 1, 2, 3, 5 and 8... as trail pattern
        i,  ii =  iv  
                  1 (first number in fibonacci)
iii     0,  1  =  1 (second number which is sum of iterator i and ii)
iii     1,  1  =  2
iii     2,  1  =  3 (ii is 1 until i is >=3) 
iii     3,  2  =  5 
iii     5,  3  =  8

@ieahleen sorry mods for sharing code … I hope that this may shed some light…