Skip to main content
added jsfiddle
Source Link
Domino
  • 499
  • 2
  • 9

#JavaScript (ES5), 68 bytes - 25 bonus = 43

alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))

(in case your browser won't allow for the snippet to run for security reasons, try this fiddle http://jsfiddle.net/thePivottt/c3v20c9g/ )

This script only works in a browser following at least DOM3 (with Node.textContent) and ECMAScript 5 (or perhaps an older version). I tried to make is as standard conforming and compatible as possible. It also assumes that the script is in the first script element of the document.

It actually concatenates multiple copies of the script itself, which is pretty awesome. Note that the snippet tool on SE puts extra whitespace around the script. We could ignore that whitespace with .trim() but I don't find it necessary considering the program is perfect without SE's meddling. Just save this HTML5 file if you want to see it run perfectly.

<!DOCTYPE html>
<html>
  <head>
    <title>Minimalist HTML5 page</title>
    <script>alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))</script>
  </head>
</html>

This script uses prompt and alert because console.log is not part of any standard, even if most modern browsers use it. If the number of repetitions passed is not a valid number or is empty, it defaults to 2. If the input is a decimal number, the program crashes due the the invalid array length.

The code uses a few interesting features of JavaScript:

  • Array(1+(+prompt()||2))

    • Array(INT) creates an Array of INT cells.

    • +prompt() takes an input and turns it into a number. If we passed the input as a string, the Array function would simply wrap it in a one-element array.

    • +prompt()||2 returns the input if it is truthy, else it returns 2.

    • This whole code creates an array of N empty elements, where N is one more than the amount of repetitions asked.

  • .join(document.scripts[0].textContent)

    • The array's join(STRING) method creates a string by concatenating all the cells, putting the provided STRING between values. In this program, there are N+1 empty elements in the array, or exactly N in-between spots. The result will be a string containing N times the provided STRING.

    • document.scripts[o] is the first <script> element of the document.

    • The textContent of Node instances returns the whole text found inside them and their child nodes, including scripts.

#JavaScript (ES5), 68 bytes - 25 bonus = 43

alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))

This script only works in a browser following at least DOM3 (with Node.textContent) and ECMAScript 5 (or perhaps an older version). I tried to make is as standard conforming and compatible as possible. It also assumes that the script is in the first script element of the document.

It actually concatenates multiple copies of the script itself, which is pretty awesome. Note that the snippet tool on SE puts extra whitespace around the script. We could ignore that whitespace with .trim() but I don't find it necessary considering the program is perfect without SE's meddling. Just save this HTML5 file if you want to see it run perfectly.

<!DOCTYPE html>
<html>
  <head>
    <title>Minimalist HTML5 page</title>
    <script>alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))</script>
  </head>
</html>

This script uses prompt and alert because console.log is not part of any standard, even if most modern browsers use it. If the number of repetitions passed is not a valid number or is empty, it defaults to 2. If the input is a decimal number, the program crashes due the the invalid array length.

The code uses a few interesting features of JavaScript:

  • Array(1+(+prompt()||2))

    • Array(INT) creates an Array of INT cells.

    • +prompt() takes an input and turns it into a number. If we passed the input as a string, the Array function would simply wrap it in a one-element array.

    • +prompt()||2 returns the input if it is truthy, else it returns 2.

    • This whole code creates an array of N empty elements, where N is one more than the amount of repetitions asked.

  • .join(document.scripts[0].textContent)

    • The array's join(STRING) method creates a string by concatenating all the cells, putting the provided STRING between values. In this program, there are N+1 empty elements in the array, or exactly N in-between spots. The result will be a string containing N times the provided STRING.

    • document.scripts[o] is the first <script> element of the document.

    • The textContent of Node instances returns the whole text found inside them and their child nodes, including scripts.

#JavaScript (ES5), 68 bytes - 25 bonus = 43

alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))

(in case your browser won't allow for the snippet to run for security reasons, try this fiddle http://jsfiddle.net/thePivottt/c3v20c9g/ )

This script only works in a browser following at least DOM3 (with Node.textContent) and ECMAScript 5 (or perhaps an older version). I tried to make is as standard conforming and compatible as possible. It also assumes that the script is in the first script element of the document.

It actually concatenates multiple copies of the script itself, which is pretty awesome. Note that the snippet tool on SE puts extra whitespace around the script. We could ignore that whitespace with .trim() but I don't find it necessary considering the program is perfect without SE's meddling. Just save this HTML5 file if you want to see it run perfectly.

<!DOCTYPE html>
<html>
  <head>
    <title>Minimalist HTML5 page</title>
    <script>alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))</script>
  </head>
</html>

This script uses prompt and alert because console.log is not part of any standard, even if most modern browsers use it. If the number of repetitions passed is not a valid number or is empty, it defaults to 2. If the input is a decimal number, the program crashes due the the invalid array length.

The code uses a few interesting features of JavaScript:

  • Array(1+(+prompt()||2))

    • Array(INT) creates an Array of INT cells.

    • +prompt() takes an input and turns it into a number. If we passed the input as a string, the Array function would simply wrap it in a one-element array.

    • +prompt()||2 returns the input if it is truthy, else it returns 2.

    • This whole code creates an array of N empty elements, where N is one more than the amount of repetitions asked.

  • .join(document.scripts[0].textContent)

    • The array's join(STRING) method creates a string by concatenating all the cells, putting the provided STRING between values. In this program, there are N+1 empty elements in the array, or exactly N in-between spots. The result will be a string containing N times the provided STRING.

    • document.scripts[o] is the first <script> element of the document.

    • The textContent of Node instances returns the whole text found inside them and their child nodes, including scripts.

Source Link
Domino
  • 499
  • 2
  • 9

#JavaScript (ES5), 68 bytes - 25 bonus = 43

alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))

This script only works in a browser following at least DOM3 (with Node.textContent) and ECMAScript 5 (or perhaps an older version). I tried to make is as standard conforming and compatible as possible. It also assumes that the script is in the first script element of the document.

It actually concatenates multiple copies of the script itself, which is pretty awesome. Note that the snippet tool on SE puts extra whitespace around the script. We could ignore that whitespace with .trim() but I don't find it necessary considering the program is perfect without SE's meddling. Just save this HTML5 file if you want to see it run perfectly.

<!DOCTYPE html>
<html>
  <head>
    <title>Minimalist HTML5 page</title>
    <script>alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))</script>
  </head>
</html>

This script uses prompt and alert because console.log is not part of any standard, even if most modern browsers use it. If the number of repetitions passed is not a valid number or is empty, it defaults to 2. If the input is a decimal number, the program crashes due the the invalid array length.

The code uses a few interesting features of JavaScript:

  • Array(1+(+prompt()||2))

    • Array(INT) creates an Array of INT cells.

    • +prompt() takes an input and turns it into a number. If we passed the input as a string, the Array function would simply wrap it in a one-element array.

    • +prompt()||2 returns the input if it is truthy, else it returns 2.

    • This whole code creates an array of N empty elements, where N is one more than the amount of repetitions asked.

  • .join(document.scripts[0].textContent)

    • The array's join(STRING) method creates a string by concatenating all the cells, putting the provided STRING between values. In this program, there are N+1 empty elements in the array, or exactly N in-between spots. The result will be a string containing N times the provided STRING.

    • document.scripts[o] is the first <script> element of the document.

    • The textContent of Node instances returns the whole text found inside them and their child nodes, including scripts.