I’m planning on using JavaScript to enter an informatics competition (BIO) tomorrow. However, I can’t rely on the examiner having a browser with a decent JavaScript engine, so I was hoping to use Microsoft’s JScript instead.
However, the documentation is, quite frankly, crap. Can someone post some example code that reads in a line of text, calls foo(string) on it, and echos the output to the command line?
Similarly, how do I actually run it? Will wscript.exe PATH_TO_JS_FILE do the trick?
If you’re using the command-line, I’d execute the script using
CSCRIPT.EXE.ie:
CSCRIPT.EXE myscript.jsThis is because
WScript.EchofromWSCRIPTwill create a dialog box and fromCSCRIPToutputs a line to the console. Run this in a command window (CMD).Reading a line from console into variable:
Where
StdInis a TextStream object. There is also anStdOutwhich can be used in place ofWScript.Echo()…Writing the output of
foo(x)to console: (must run underCSCRIPT)You can use the
WScriptobject to determine which engine you are running under, there’s a question/answer for that (VBScript, but uses the same objects under JScript) here.