JSFiddle - React, Tailwind, and code Playground
by mLuby
HTML
<body>
<input type="number">
<button>Submit</button>
<h1 id="result">Result</h1>
</body>
JavaScript
/*
Write a function to find a Fibonacci-like result, based on the following
function:
F(n) = square(n), for 0 <= n <= 6
F(n) = F(n-3) + F(n-7)
*/
var f = function(n){
if(n<=6){
return n*n;
} else {
return f(n-3) + f(n-7);
}
};
$(document).ready(function(){
$('button').click(function(){
$('#result').text(f($('input').val()));
});
});