Simple text interface for easy imperative programming for beginners
Beginning programmers often want to write something simple like:
const name = readText("What's your name?");
print('Hello, ' + name + '!');
This library is meant to facilitate that kind of programming in a web-based environment. It is of course impossible to program in this way on the web, but using top-level await we can come close.
This library works like this:
const ti = new TextInterface();
ti.output('What is your name?');
let name = await ti.readText();
ti.output('Hello, ' + name + '!');
We also have:
- ti.readNumber() - returns a number
- ti.readYesOrNo() - returns a true or false value
- ti.readChoice(['A','B','C','D']); - takes a list of choices as an argument and returns one of the choices.
The goal is to give students a very simple input/output way of interacting with users and present it on a web page in a way kids can build a project and present it.
Since this happens on the web, we need to use await of course to wait for user input without blocking the web page. We present the interface in an old-school looking terminal-like interface, though that's customizable with CSS.