Go Pump — Go

Program Mbak Erna's fuel pump with real Go: go build, operators, if and functions. 17 levels, played right in the browser with nothing to install.

What you learn in this game

Go is a compiled language: the compiler checks all of the code first, then makes one program file. Every Go file starts with a package line, then its import list, then its functions. At Mbak Erna's kiosk every program is built and run by real Go 1.27, and the pump's display copies exactly what it prints.

Operators work things out (+ - * / %), compare (== != < > <= >=) and join conditions (&& || !). *, / and % go before + and -. Dividing two ints drops the fraction, and % gives the remainder. From this level on, the numbers on the pump's display are what villagers pay.

if runs a block of code when its condition is true. else if and else add other branches, and only one branch runs. The condition has no brackets, the braces are required, and { sits on the same line as if.

A function is a named piece of code that takes values in and can give a result back: func name(parameter type) resultType. Go can also return more than one value, and the caller catches them all.