Skip to main content
4 of 5
added 7 characters in body
Mama Fun Roll
  • 9.9k
  • 1
  • 36
  • 46

#Javascript ES6 (REPL), 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

Mama Fun Roll
  • 9.9k
  • 1
  • 36
  • 46