Skip to content

Instantly share code, notes, and snippets.

@pajaro5
Last active June 26, 2019 02:34
Show Gist options
  • Save pajaro5/116dc5e5f590823571a340b933cd5788 to your computer and use it in GitHub Desktop.
Save pajaro5/116dc5e5f590823571a340b933cd5788 to your computer and use it in GitHub Desktop.
ejemplo de repetidor ascendente
<!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">
<title>Recursividad ejemplo arriba</title>
</head>
<body>
<h1>Ejemplo ascendente de recursividad</h1>
</body>
<script>
//Ejemplo que imprime en la consola los números en forma ascendente hasta el máximo ingresado por el usuario.
var numeroMaximo = parseInt(prompt("Oye ingresa un número: ")); //4
//var contador = 1;
var repetidor = function(contador) {
if (contador > numeroMaximo) {
console.log('fin');
} else {
//logica de negocio
console.log('contador: ' + contador);
return repetidor(contador+1);
}
}
repetidor(1);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment