Provides a web console HTML page with print and input functions for JavaScript. A demonstration with a simple number-guessing game is available on this repository's github-pages.
-
Copy webconsole.js and webconsole.css (optional, but required if you want to use dark mode) into your project (I'm working on setting up a CDN---you can try using https://reeceyang.github.io/webconsole/webconsole.js for now). You can also add this repository as a git submodule.
-
Include webconsole.js and webconsole.css in your .html file. Call
Webconsole.addTo(element);
to append Webconsole to the contents ofelement
, whereelement
is a JS DOM object. For example,
Webconsole.addTo(document.body);
adds Webconsole to the document body. Call Webconsole.addDarkModeTo(element);
to add a dark mode toggle button to the start of the contents of element
.
- Write your code in an asynchronous main function:
async function main() {
// do stuff
}
- Call the main function to run your program:
main();
Prints all arguments to the console, one after another.
Prints all arguments to the console, one after another, with a line break at the end.
Clears the content of the console output.
Prints all arguments to the console, then waits for the user to input a value. Then prints a line break at the end, and returns that value. Note: you must place a await
in front because input()
is an asynchronous function.