Simple Web Basic

Copyright © 2010 Yohanes Nugroho

This is a simple implementation of unstructured BASIC (uses line numbers) in JavaScript. You can type in your source code, and run it in your browser. INPUT statement will become HTML input form. The source code is here.

Click here to see other things that I've made.

Other BASIC/JavaScript projects by other people:

Help

Keywords

Although I haven't tested most of them, the following keywords should work: IF THEN ELSE FOR TO STEP GOTO GOSUB RETURN NEXT INPUT LET CLS END PRINT DIM DATA READ REM END OR AND MOD WHILE WEND RANDOMIZE SYSTEM CLEAR. Other keywords (ON GOTO, ON GOSUB, ON ERROR, RESUME, etc) are not implemented. PRINT doesn't support USING.

Functions

The following functions should work: VAL STR$ LEFT$ RIGHT$ MID$ LEN RND INT INSTR ABS ASC CHR$ SQR STRING$ SIN COS TAN TIMER

Test Code

Here are some code that you can run

I/O Example

Example to show how INPUT is displayed as HTML Form

10 INPUT "What is your name?", NAME$
20 INPUT "Input a number ", A
30 FOR I=1 TO A
40 PRINT "Hello "; NAME$
50 NEXT I

Reverse Phrase

Taken from here (unmodified source).

10 REM Reverse the letters of a phrase
20 CLEAR :KEY OFF :CLS
30 INPUT "What is your phrase";PHRASE$
40 PRINT :PRINT "The phrase reversed: ";
50 FOR LETTER = 1 TO LEN(PHRASE$)
60   PRINT LEFT$(RIGHT$(PHRASE$,LETTER),1);
70 NEXT LETTER
80 END

Armstrong Numbers

Taken from here.

10 ' PROGRAM Armstrong Numbers
20 CLS
30 PRINT "ARMSTRONG NUMBERS" :PRINT
40 PRINT "Program computes all Armstrong numbers in the range of 0 - 999."
50 PRINT "An Armstrong number is a number such that the sum of its digits"
60 PRINT "raised to the third power is equal to the number itself." :PRINT
70 '
80 '   A, B, C                             the three digits
90 '   ABC, A3B3C3                         the number and its cubic sum
100 '   COUNT                              a counter
110 '
120 A=0: B=0: C=0: COUNT=0                 'initialise
130 FOR A = 0 TO 9                         'for the left most digita
140   FOR B = 0 TO 9                       'for the middle digit
150     FOR C = 0 TO 9                     'for the right most digit
160       ABC = A*100 + B*10 + C           'the number
170       A3B3C3 = A^3 + B^3 + C^3         'the sum of cubes
180       IF ABC = A3B3C3 THEN GOSUB 230   'if they are equal
190     NEXT C
200   NEXT B
210 NEXT A
220 END
230 ' Display results subroutine
240 COUNT = COUNT + 1                      'count the Armstrongs
250 PRINT "Armstrong number"; COUNT;": "; ABC
260 RETURN

99 Bottles of beer

Slightly modified from basic version for apple 1 basic (I changed # to <>).

1 REM A SUBSTANTIAL PART TAKEN
2 REM FROM THE BASIC EXAMPLE.
3 REM FIXED S GRAMMAR AND 
4 REM FORMATED TO FIT APPLE 1
5 REM SCREEN
6 REM
7 REM PROGRAMED ON THE APPLE 1
8 REM REPLICA BY VINCE BRIEL.
9 REM 
10 FOR X=99 TO 1 STEP -1
20 Y=X-1
30 PRINT X;" BOTTLE";
40 IF X<>1 THEN PRINT "S";
50 PRINT " OF BEER ON THE WALL,"
60 PRINT X;" BOTTLE";
70 IF X<>1 THEN PRINT "S";
80 PRINT " OF BEER"
90 PRINT "TAKE ONE DOWN AND PASS IT AROUND,"
100 PRINT X-1;" BOTTLE";
110 IF Y<>1 THEN PRINT "S";
120 PRINT " OF BEER ON THE WALL"
130 PRINT ""
140 NEXT X
150 END

Source Code


Hide source code while executing

Execution result