Go typing test
Go is deliberately plain: few keywords, no semicolons at the ends of lines, no parentheses around conditions and one standard formatting style. That makes it quick to type once you know its quirks: := to declare variables, package main and an import at the top of every program, and fmt.Println with a capital P.
What you'll type in Go
:=to declare and assign in one step, as ini := 1.package mainandimport "fmt"at the start of almost every program.fmt.Println: a dot and a capital P.*and&for pointers, as in*Nodeand&Node{value: value}.[]int{...}slices and_, v := rangeloops.- Semicolons only inside
forloop headers, as infor i := 1; i <= 15; i++.
Example: FizzBuzz in Go
Go has no else if chain here: a bare switch with case lines does the work, and the for loop has no parentheses.
package main
import "fmt"
func main() {
for i := 1; i <= 15; i++ {
switch {
case i%15 == 0:
fmt.Println("FizzBuzz")
case i%3 == 0:
fmt.Println("Fizz")
case i%5 == 0:
fmt.Println("Buzz")
default:
fmt.Println(i)
}
}
}
Tips for typing Go faster
- Habit may make you type parentheses around conditions. In Go,
ifandforgo straight to the condition. :=is Shift + semicolon followed by an unshifted equals sign. Practise letting go of Shift in between.- Go code uses short names like
i,vandn, so most of your time goes on keywords and symbols. Focus your practice there.
All 20 Go programs
Every program is real, working Go. Choose one to start typing it straight away.
Beginner
- Hello, World!Print a greeting.
- Count to fivePrint the numbers 1 to 5.
- Celsius to FahrenheitConvert 100 °C to Fahrenheit.
- Sum a listAdd up 3, 1, 4, 1, 5.
- Find the largestFind the biggest number in a list.
- Count vowelsCount the vowels in "keyboard".
Intermediate
- Reverse a stringTurn "hello" into "olleh".
- FizzBuzzFizz for 3s, Buzz for 5s, 1 to 15.
- FactorialA recursive function, called with 5.
- FibonacciPrint the first ten Fibonacci numbers.
- Greatest common divisorEuclid's algorithm for 48 and 18.
Advanced
- Primes to 20Print every prime up to 20.
- PalindromeCheck whether "racecar" reads the same backwards.
- Word countCount the words in a sentence.
- Bubble sortSort 5, 2, 9, 1, 7 by swapping neighbours.
- Binary searchFind 7 in a sorted list by halving.
Expert
- QuicksortSort a list by partitioning around a pivot.
- Binary search treeBuild a tree, then read the values back in order.
- Shortest path (BFS)Breadth-first search through a small graph.
- N-QueensCount the ways to place 6 queens so none attack.
How the test works
The timer starts on your first key and stops once every character is right. Press Enter for a new line and the indentation is filled in for you. A wrong key shows in red and counts as a mistake; press Backspace to go back and fix it. Your best time for each program is saved in your browser. Read more about how speed and accuracy are calculated, or get tips for typing code faster.