Skip to content

Instantly share code, notes, and snippets.

@sauloco
Created February 17, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauloco/df8aafb64da1049feff37851907cb509 to your computer and use it in GitHub Desktop.
Save sauloco/df8aafb64da1049feff37851907cb509 to your computer and use it in GitHub Desktop.
<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