Created
February 17, 2018 02:59
-
-
Save sauloco/df8aafb64da1049feff37851907cb509 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
</head> | |
<body> | |
Generar <input type="number" min = 1 max = 99 value = 0 onchange="document.getElementById('target').innerHTML = generate(this.value);"> veces: <br> | |
<div id = target></div> | |
</body> | |
<script> | |
/** | |
* params | |
* times: integer, times to repeat the pharagraph generated. | |
* | |
* returns | |
* string, the pharagraph generated with the lyric repeated `times` times. | |
*/ | |
function generate(times){ | |
return r(times, | |
r(1, "Scooby doo papa") + | |
r(3, "y el " + r(5, "pum"),false) + | |
r(6, "pum") + | |
r(1, "y la cosa suena" ) + | |
r(5, "ra") | |
) | |
} | |
/** | |
* params | |
* c: integer, times to repeat the phrase | |
* s: string, phrase to repeat | |
* nl: boolean, optional, default value true, if true add a new line tag for HTML <br> | |
* | |
* returns | |
* string, the phrase plus a space and the html new line tag added by default or skipped if nl is false | |
*/ | |
function r(c,s,nl = true){ | |
return (s+(" ")).repeat(c)+(nl ? "<br>" : "") | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment