Skip to content

Instantly share code, notes, and snippets.

@anthony17guty
Created August 2, 2019 01:47
Show Gist options
  • Save anthony17guty/529a0dd76e990283a45f6dd6628aacea to your computer and use it in GitHub Desktop.
Save anthony17guty/529a0dd76e990283a45f6dd6628aacea to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Document</title>
</head>
<h1> Serie de Fibonacci</h1>
<body>
<input type="number" id="numeroInicial" name="primerNumero">
<br>
<input type="number" id="numeroFinal" name="segundoNumero">
<br>
<input type="number" id="maximo" name="maximo">
<br>
<input type="button" id="btnGenerar" value="Generar">
<br>
<table id="fibonacci1" border="4">
<thead>
<th>serie Fibonacci</th>
</thead>
<tbody id="serieFibonacci">
</tbody>
</table>
<table id="fibonacci2" border="4">
<thead>
<th></th>
</thead>
<tbody id="serieFibonacci1">
</tbody>
</table>
<table id="fibonacci3" border="4">
<thead>
<th></th>
</thead>
<tbody id="serieFibonacci2">
</tbody>
</table>
<table id="fibonacci4" border="4">
<thead>
<th></th>
</thead>
<tbody id="serieFibonacci3">
</tbody>
</table>
</body>
<script>
var index=0
var seriefibo=document.getElementById("serieFibonacci");
document.getElementById("btnGenerar").addEventListener("click",function mostrar(){
divFibo.style.display="block"
if(index>serie.length-1){
return 0;
}else{
var fila=document.createElement("tr")
var fila1=document.createElement("tr")
var fila2=document.createElement("tr")
var columna=document.createElement("td")
var columna1=document.createElement("td")
var columna2=document.createElement("td")
columna.appendChild( document.createTextNode(serie[index]))
columna1.appendChild( document.createTextNode(serie[index+1]))
columna2.appendChild( document.createTextNode(serie[index+2]))
fila.appendChild(columna)
fila.appendChild(columna1)
fila.appendChild(columna2)
seriefibo.appendChild(fila)
seriefibo.appendChild(fila1)
seriefibo.appendChild(fila2)
index+=3
mostrar(index)
}
})
</script>
<script>
var serie=[]
class solver{
constructor(primerNumero,segundoNumero,maximo){
this.primerNumero=primerNumero;
this.segundoNumero=segundoNumero;
this.maximo=maximo;
}
}
</script>
<script>
document.getElementById("btnGenerar").addEventListener("click",function(){
var maximo1=(document.getElementById("maximo").value);
var n1= (document.getElementById("numeroInicial").value);
var n2= (document.getElementById("numeroFinal").value);
serie.push(parseInt(n1),parseInt(n2))
function fibonacci (nu1,nu2){
if(nu1+nu2>maximo1){
return serie;
}else{
nuevoNumero=nu1+nu2
serie.push(nuevoNumero)
return fibonacci(nu2,nuevoNumero)
}
}
console.log(fibonacci(serie[0],serie[1]))
})
</script>
<script>
//divisiones
var divFibo=document.getElementById("fibonacci1")
var divFibo1=document.getElementById("fibonacci2")
var divFibo2=document.getElementById("fibonacci3")
var divFibo3=document.getElementById("fibonacci4")
//ocultar divisiones
divFibo.style.display="none"
divFibo1.style.display="none"
divFibo2.style.display="none"
divFibo3.style.display="none"
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment