Build a tiny application
Two small programs that use everything from the first lessons: a console tip calculator and a small web page.
A tip calculator
ask asks the person running the program. Whatever they type is turned into a number when it looks like one.
Otter
ask "Bill amount: " and call it bill
ask "Tip rate (percent): " and call it rate
bill times rate make product
product divided by 100 make tip
bill and tip make total
say "Tip:" tip
say "Total:" total
Save it as tip.ot and run otter tip.ot. With 50 and 20 typed in, it prints:
Output
Tip: 10
Total: 60
Each statement does one thing, so a longer calculation is several short lines. That is what keeps Otter readable.
Checking guesses
Conditions and loops turn the same ideas into a game:
Otter
secret is 7
guesses are
3
9
7
.
each guess in guesses
if guess is less than secret
say guess "is too low"
otherwise if guess is greater than secret
say guess "is too high"
otherwise
say guess "is correct!"
.
.
A small web page
The same language describes a web page. Save this as greeter.ot and run otter web greeter.ot:
Otter
app is a page with title "Greeter", width 560, spacing 14
nameBox is a text box with placeholder "Your name"
helloButton is a button with text "Say hello"
message is a text with value "Waiting..."
when helloButton is clicked
text of message is text of nameBox
.
put nameBox, helloButton, message in app
show app
Otter writes a single HTML file you can open in any browser. Change the words, add a second button, and run it again.
Web applications
Where to go next