// How to play
Type a number between 1000 and 2000 and press Enter. The program casts its spell, then tells you whether you guessed its number, both numbers, the difference, and what it thinks of you. The screen clears at the end: press any key to try again. On a phone, use the keys under the window (⌨ opens the full keyboard).
// Revisited
Rebuilt from Magic.bas (April 2001), which QuickBASIC 4.5 saved in its binary, tokenized format rather than as text. A small detokenizer written for this port decoded the whole program: every opcode was identified, the 48 lines match the line count QB stored in the file, and an independent decoder (qb45detok) gives the same listing. The JavaScript follows it line by line, with the original line numbers and variable names (B, a, w, q, g, x, y, z).
It is a text-mode program. The file's name table also holds RADIUS, PI, StartAngle and EndAngle (the names in the CIRCLE example of QB's help), plus d1 to d8 and a few typos. QuickBASIC never deletes a name once it has been typed, and no statement in the program uses them, so there is no graphics part to port.
The spell prints its line once for every step of the secret number (1000 to 1999 times), with RANDOMIZE TIMER before each of its three RND calls. The page uses QuickBASIC's own RND generator and RANDOMIZE seeding with an 18.2 Hz TIMER, so the colours come from the same arithmetic. New lines scroll in with the current background colour, as in QB, which gives the two-tone stripes. How fast the loop ran depended on the PC. Here it runs at about 1000 lines a second. The texts are the original ones, typed in code page 850 (hence IMBÈCIL). Keys typed early wait in the keyboard buffer and cut the next SLEEP short, as in DOS. INPUT uses a comma, so QuickBASIC showed no ? after the prompt. The program ends with CLS and END. As in the QuickBASIC environment, the page then shows Press any key to continue, and here a key runs it again.