Commit 9c17b848 authored by Rodrigo Diez's avatar Rodrigo Diez

Generador aleatorio

parent ec6c7fa2
......@@ -3,9 +3,45 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mini.css/3.0.1/mini-default.min.css">
<title>Simulacion Loteria</title>
</head>
<body>
<header class="sticky">
<!--
<a href="#" role="button">Home</a>
<a href="#" role="button">About</a>
<a href="#" role="button">Contact</a>
-->
</header>
<br />
<div class="container">
<div class="row">
<div class="col-sm">
</div>
<div class="col-sm-12 col-md-8 col-lg-6" style="height: calc(100vh - 10.25rem); display: flex; align-items: center; flex: 0 1 auto;">
<form>
<fieldset>
<legend>Generar numero</legend>
<div class="input-group fluid">
<label for="numero">Numero</label>
<input type="text" value="12345" id="numero" placeholder="Numero">
</div>
<div class="input-group fluid">
<a type="button" class="primary" id="generar">Generar</a>
</div>
</fieldset>
</form>
</div>
<div class="col-sm">
</div>
</div>
</div>
<footer>
<p>Copyright &copy; DiezRoFer 2019</p>
</footer>
<script src="js/script.js"></script>
</body>
</html>
\ No newline at end of file
/**
* @description Genera una cifra aleatoria del 0 al 9.
*/
function cifraAleatoria(){
return parseInt(Math.random()*9)
}
/**
* @description Genera un numero aleatrorio de 5 cifras.
*/
function numeroAleatorio(){
let numero = [];
for (i = 0; i < 5; i++){
numero[i] = cifraAleatoria();
}
return numero;
}
/**
* @description Genera una String a partir de un numero de 5 cifras
* @param {array} numero Un array con cinco cifras
*/
function numeroToString(numero){
let string = "";
for (i = 0; i < 5; i++){
string += numero[i];
}
return string;
}
let generarBTN = document.getElementById("generar");
let numeroINPUT = document.getElementById("numero");
generarBTN.addEventListener("click", ()=>{
let numero = numeroToString(numeroAleatorio());
console.log(numero);
numeroINPUT.value = numero;
})
//console.log(numeroToString(numeroAleatorio()));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment