go · level 1 · unit 1 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Every Go program sits in the same frame.
Here is the frame, line by line. says this is a program you can run. brings in fmt, a toolbox for showing text. func main() { is where your program starts, and the last } is where it ends.
Your instructions go in between. shows whatever is inside its brackets, then moves to a new line. You will write this frame every time, so it soon feels like home.
Words go inside double quote marks, like "Hello, world!". A piece of text in quotes is called a . The quotes tell Go where the text starts and stops, and they are not shown.
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
} Always use double quotes for a string, because single quotes mean something different in Go.
guess first
What will appear on the screen?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
package main
import "fmt"
func main() {
fmt.Println("My cat is called Pickles")
}
your turn
Your turn. Tell the computer what you love to eat.
Type your favourite food in place of the blank, keeping it inside the quotes. Then press run.
output
press run to see what happens
fix it
This program will not run. Can you fix it?
output
press run to see what happens
- Look at what comes straight after
fmt.Println. fmt.Printlnneeds brackets to hold the string it shows. Are there any?- Put ( after Println and ) at the very end of the line, then press run.
nailed it
you made the computer talk. :D
- Every program needs
package main,import "fmt"andfunc main(). fmt.Printlnshows whatever is inside its brackets.- Text inside double quote marks is called a string.
new words in your collection
- package
- import
- Println
- string
This lesson isn’t saved. A free account remembers every lesson you finish.