Welcome to the interactive JohnnyBASIC programming guide.
If you've never programmed a computer before, this guide will get you started.
We'll start with the basics and gently introduce the topic of writing programs.
Johnny BASIC is a safe "sandbox" environment, so don't worry! You can't break anything.
You can mess around with the examples as much as you like. It's quite safe, I promise.
Programming, in its simplest form, involves giving the computer a list of step-by-step instructions.
Computers are very good at following instructions, as long as they're written in a language the computer understands. Here, we use a simple language called BASIC, which was created at Dartmouth College in 1964 for liberal arts students!
It has a simple structure: each line begins with a command word that
chooses the action to take.
Commands are typically followed by some parameters,
which differ from one command to another.
Let's try something! The following box is a scratchpad that allows commands to be entered for the computer to follow (or, execute!)
Click or tap on the box below and try typing in the command:
print "hello"
Press the RETURN key to execute the command. The computer will follow the instruction immediately.
Tip: the punctuation is important; computers are picky about using quote marks "" (next to the RETURN key [USA] or above 2 [Europe]) and punctuation symbols in the right places—but not the right places for human languages! They must be in the right places for the Programming Language, BASIC. In this example, the quotes surround the letters you wish to print out.
If the computer doesn't undestand your instruction, it will come back with a message like Unrecognised statement (i.e. the command word) or Missing ". It's trying to be helpful! These messages all mean the same thing: the computer didn't entirely understand the command (it's not very smart.) Usually the message provides a hint at the problem. Check that the command is spelled correctly and the quote symbols are paired up.
The print command can also print out numbers:
print 42
Actually, you can request calculations and ask the computer to print out the result as well:
print 5 + 2
print 2 * 8 - 6
Try entering your own formulas—experiment!
You can combine all of the above, asking the computer to print a combination of things:
print "My age is" 5*6 "and I am happy!"
print "It takes" 3*24 "steps to get there and" 2^5+8 "steps to get home."
Tip: Enter each command entirely on a single line, even if it starts scrolling across horizontally as you type it. The computer will become confused if you try to break up a single command across multiple lines!
Tip: remember that the quote marks "" go around letters you wish to print out literally.
If you leave them out, the computer will try to make sense of the letters as a mathematical
formula, and it will become quickly confused.
Previous Chapter Leave the Guide