JSFiddle - React, Tailwind, and code Playground
by mgibsonbr
HTML
<input><button>Calcular</button>
<div id="out"></div>
JavaScript
function fib(n) {
var a = 1;
var b = 1;
var temp;
while ( n > 2 ) {
temp = b;
b = a + b;
a = temp;
n--;
}
return b;
}
$("button").click(function() {
var n = parseInt($("input").val(), 10);
$("#out").append("<p>" + fib(n) + "</p>");
});