JSFiddle - React, Tailwind, and code Playground

by DustyWhite

JavaScript

function fibonacciSum() {

  //DS: First I need some variables to play with. I will add more of them as I need to this area to keep them tidy:
  var base = 0;
  var addThis = 1;
  var runningTotal;
  var stop = 15
  var arr = []

  // Now we add our friens "mister Loop" to start counting numbers (incrementing one at a time so we do not miss any):
  for (var i = 0; i <= [fibonacciSum.length + stop]; i++) {

    //DS: Here is where it gets tricky . . . We need to add 1 to 0, and then store that as (0 + 1) in a new variable. Then we need to be able repeat that process over and over, but with the new numbers as we go along. BUT we must define the empty variable first or javascript gets all wonky and starts throwing NaN's at us. This part tripped me up. Each time we look we will add a new number (addThis) to our base number to get the runningTotal number. 
    runningTotal = base + addThis;
    base = addThis;
    addThis = runningTotal;

    //DS: This is a **really** good time to test our logic, but first let's get rid of those pesky EVEN numbers that no one likes anyway.
    if (runningTotal % 2 !== 0) {
      console.log("The current total is: " + runningTotal + " and our array is currently " + arr.length + " numbers long." + " We need " + (11 - arr.length) + " more odd numbers!");
      //DS: So far so good! Now we need to PUSH each new number into an ARRAY to sort them out and make it easy to add up the total at the end: 
      arr.push(runningTotal);
      //DS: Test test test!
      console.log(arr);

    }
  }

  //DS: Now let's add 'em up!
  const result = base + addThis + runningTotal;
  console.log("The TOTAL of the first 11 Fibonacci numbers is " + result + "!")

  // Great work team! Now we simply insert that number into the HTML code to complete this assignment.
  const sumFibResult = result;
}

fibonacciSum();