This page explains how to operate
Tom's JavaScript Machine,
including some extensions that are not standard
in JavaScript.
Program Facilities
Edit your JavaScript program
in the text area in the middle of
Tom's JavaScript Machine, under Program. Warning: Your program is lost when reloading the machine page.
Save it in a local text file via copy/paste,
or via the Clone button (see below).
Run the program by clicking the Run button.
This first clears the output area.
[Advanced]
Button 'Run & Append Output' will run the program
without clearing the output area.
Run-time errors are reported through an alert window. Warning: Error messages can be uninformative,
since they do not tell where in the program text the error was triggered.
Adhering to
JavaScript
coding conventions
helps prevent errors.
To locate errors,
it can be helpful to comment out parts of the program
and run it again,
and to show intermediate values through the standard function
alert(s).
[Advanced]
Clone the machine by clicking the Clone button.
This opens a new machine window with copies of the current input, separator,
program, and output.
The title of the new window displays a clone number.
[Advanced]
The button 'Challenge' clears the input and output text areas,
runs the program, and
compares the program text to the program's output.
This is useful for the Challenge. Note: Mind possible newlines at the very end,
because these are also compared.
[Advanced]
There is no Clear button to reduce the risk of accidentally deleting
your program.
To clear the program area,
click inside, do 'Select All', and either Cut or Delete the selection,
or Paste the Clipboard over it;
alternatively, above the Output text area click 'Clear' and 'Copy to Program'.
Output Facilities
The program can write output,
which then appears in the text area on the right,
using the predefined functions
write():
writes each of its multiple arguments to output
writeln():
like write(), and appends a newline
writequ():
writes a single quote
Such output is also appended to the predefined variable
output.
(The functions write() and
writeln() are comparable to
the standard JavaScript functions
document.write() and
document.writeln(),
that 'inject' the argument strings into the HTML document.
Such 'injection' is not useful in Tom's JavaScript Machine.)
[Advanced]
To clear the output text area, click its Clear button.
[Advanced]
To copy the output to the program area,
click button 'Copy to Program' above the output area.
This is useful when a program produces as output a program
that you then want to run.
See the Examples for such programs.
Input Facilities
The program can process input from the text area on the left.
When you click Run, the text on the left is made
available in the predefined variable input.
The input is also separated into an array of strings
according to the separator
defined in the input field above the input text area
(the default separator is a space).
The separated values can be accessed one by one
using the predefined functions
readStr()
readNum()
Whether further separated input values are available is
reported by the predefined function moreInputs(). Warning: Input that is entered after the program has been started,
will not be processed in this way. Notes (for advanced use):
The separator is available
in the predefined variable separator.
This might be useful in output.
The arrray of separated input strings is available
in the predefined variable inputs.
The index of the next input value is available
in the predefined variable
nextInputIndex.
You typically do not need this variable and should not mess with it.
[Advanced]
To clear the input text area, click its Clear button.
[Advanced]
To copy the program to the input area,
click button 'Copy to Input', above the program area.
[Advanced]
To copy the output to the input area,
click button 'Copy to Input', above the output area.
Miscellaneous Predefined Functions and Constants
Some predefined functions are available to recognize characters
(not needed for the Challenge):
isQuote(c):
determines whether c is a single quote (')
isNewline(c):
determines whether c is a newline
Some special symbols are available through predefined constants
(use these sparingly; not needed for the Challenge):
QU for a single quote (')
NL for a newline:
on output, moves the writing head to next line
(like writeln());
can also be used for comparison to characters on input