JSFiddle - React, Tailwind, and code Playground
by leiperte
HTML
<input type = "button" id
<div id "output">
</div>
JavaScript
function solution()
{
var fibno = [ 1, 2 ], sum = 0;
function cal(arr )
{
return arr[ arr.length - 1 ] + arr[ arr.length - 2 ];
}
while ( fibno[ fibno.length - 1 ] < 1e+6 )
{
fibno.push( cal(fibno) );
}
fibno.forEach( function(n)
{
if ( n % 2 === 0 )
{
sum += n;
}
});
return sum;
}
//console.log(solution())
document.getElementById("output").innerHTMHL = sum;