Reputation: 946
I received the error "ERROR: expected '='" while trying to compile my code. I'm guessing it has something to do with my function definition. Can anyone help?
1 REM declare function
2 DEF FNS(a) = a * a
3
4 REM declare variables
5 LET numOne = 0.0
6 LET answer = 0.0
7
8 REM get input from user
9 INPUT "Enter a number: "; numOne
10
11 REM get answer
12 answer = FNS(numOne)
13
14 REM display answer
15 PRINT "Answer: "; FNS(numOne)
Upvotes: 2
Views: 117
Reputation: 562
Your code will work perfectly on many BASIC variants (e.g. AppleSoft - see this emulator), but not on every one.
If by JS Basic you mean this project, then realize that this variant has (as far as I know) no support for DEF FN
, so you will have to do with GOSUB
. Also, the arguments to PRINT
and INPUT
are sepparated by a simple whitespace (not semi-colon) and it is mandatory to append $
to each variable name.
I tweaked your code to work within those constraints (it runs alright in the JS Basic link above). I kept your line numbers multiplied by 10 to ease comparison.
00 GOTO 35
05
10 REM Subroutine SQUARE
15 REM Input: arg$ Output: result$
20 result$ = arg$ * arg$
25 RETURN
30
35 REM Program Start
40 REM declare variables
50 numOne$ = 0.0
60 answer$ = 0.0
70
80 REM get input from user
90 INPUT "Enter a number: " numOne$
100
110 REM get answer by calling SQUARE subroutine
112 arg$ = numOne$
115 GOSUB 10
120 answer$ = result$
130
140 REM display answer
150 PRINT "Answer: " answer$
Notice that in this variant you don't have to initialize your variables before using e.g. with INPUT
, so you don't really need lines 50 and 60.
Upvotes: 2