How can I write a simple JScript input/output program?

前端 未结 2 1283
梦毁少年i
梦毁少年i 2021-01-02 09:46

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

2条回答
  •  没有蜡笔的小新
    2021-01-02 10:32

    If you're using the command-line, I'd execute the script using CSCRIPT.EXE. ie: CSCRIPT.EXE myscript.js This is because WScript.Echo from WSCRIPT will create a dialog box and from CSCRIPT outputs a line to the console. Run this in a command window (CMD).

    Reading a line from console into variable:

    var x = WScript.StdIn.ReadLine();
    

    Where StdIn is a TextStream object. There is also an StdOut which can be used in place of WScript.Echo()...

    Writing the output of foo(x) to console: (must run under CSCRIPT)

    WScript.Echo(foo(x));
    

    You can use the WScript object to determine which engine you are running under, there's a question/answer for that (VBScript, but uses the same objects under JScript) here.

提交回复
热议问题