Created
July 10, 2019 18:19
-
-
Save SamuelNittala/19943f62a7ee9d91971b080a8ff0eb30 to your computer and use it in GitHub Desktop.
Fibonacci Finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fibonacci Finder | |
---------------- | |
A [Pen](https://codepen.io/bumchik/pen/pXGajw) by [Samuel Nittala](https://codepen.io/bumchik) on [CodePen](https://codepen.io). | |
[License](https://codepen.io/bumchik/pen/pXGajw/license). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<title> Fibonacci finder </title> | |
<div class="main"> | |
<h1 id="fib">Fibonacci Finder</h1> <br/> | |
<label id="num"for="number"> ENTER NUMBER </label> | |
<input type="text" id="number"/> | |
<button id="result"> Submit </button> | |
<h1 id="output"> </h1> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mem = [0,1] | |
function fib(i){ | |
if(i ==0 || i==1) return mem[i] | |
else if(i>=mem.length){ | |
mem[i] = fib(i-1) + fib(i-2) | |
return mem[i] | |
} | |
else return mem[i] | |
} | |
var b = document.getElementById("result") | |
b.addEventListener("click",res) | |
function res(){ | |
var ip = parseInt(document.getElementById('number').value) | |
console.log(ip) | |
document.getElementById('output').innerHTML = "Fibonacci value is " + fib(ip) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url('https://fonts.googleapis.com/css?family=Lato&display=swap'); | |
.main{ | |
padding:5px; | |
background-color:#faff7f; | |
font-family: 'Lato', sans-serif; | |
} | |
#num{ | |
color:#ff5154; | |
font-size:20px; | |
padding:10px; | |
margin-left:15px; | |
font-weight:bold; | |
} | |
input{ | |
margin:10px; | |
width:100px; | |
height:20px; | |
border:2px solid #ff88dc; | |
} | |
#fib{ | |
text-align:center; | |
color:#ff88dc; | |
} | |
#output{ | |
color:#8497e8; | |
padding:10px; | |
margin-left:15px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment