# recursion/fibonacci.js (via loops)

## In this example below you will see how to do a recursion/fibonacci.js (via loops) with some HTML / CSS and Javascript

This awesome code was written by alexsales, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
• HTML
• JavaScript
``````<!DOCTYPE html>
<html lang="en" >

<meta charset="UTF-8">
<title>recursion/fibonacci.js (via loops)</title>

<body>

<div class="fibonacciArray"></div>

<script  src="js/index.js"></script>

</body>

</html>
``````
``````
var fullFibArray = [];
var nArray = [];
var fibArray = [0, 1, 1];

function setView(_obj) {
document.getElementsByClassName('fibonacciArray')[0].innerHTML += _obj.n + ', ' + _obj.fib + '<br/>';
}

function combineArrays(_n) {
var obj = {};

for (var i = 0; i <= _n; i++) {
obj.n = i;
obj.fib = fibArray[i];
fullFibArray.push(obj);

setView(obj);
}
console.log(fullFibArray);
}

function fillFibArray(_n) {
for (var i = 0; i <= _n; i++) {
var sum = 0;

/*console.log(fibArray[i]);*/
sum = fibArray[i] + fibArray[i + 1];
fibArray[i + 2] = sum;
}
console.log(fibArray);
}

function fillNArray(_n) {
for (var i = _n; i >= 0; i--) {
nArray.unshift(i);
}
console.log(nArray);
}

fillNArray(10);
fillFibArray(10);
combineArrays(10);

/*console.log(nArray.length);*/
``````