Below, you can find another hint for the Challenge.
You should only get here after reading, digesting, and applying the .
Because we decided earlier that each line in the output is terminated by a newline, we know that the string literal S contains a newline marker as last character: S.charAt(S.length - 1). This occurence can be used to recognize newline markers, without the need for incorporating the marker itself or any extra quotes in the program:
that this program outputs itself:
What remains to be done is splitting the string literal that defines S across multiple lines. There are various approaches possible. JavaScript does not allow you to break up a single string literal across multiple lines ():
This will cause the error message SyntaxError: Parse error.
N.B. This can be repaired by using an advanced feature of JavaScript, viz. using a backslash to indicate that a string literal continues on the next line ():
But we consider this cheating (by using advanced JavaScript features).
Another way of accomplishing the same effect is the use of a string expression involving multiple string literals that are concatenated through the plus operator ():
Can you incorporate this idea into the program above?
Try your program in the machine, and see if you can extend it to a complete solution.
It is your turn ...
If you tried this hint, or do not see how it helps, then you are ready for the .