go · level 1 · unit 1 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Lines run in order, one after another.
A program can have lots of lines. Go runs them in order, top to bottom, like ticking off a shopping list. Everything your program shows on the screen is called its .
An empty fmt.Println() has nothing to show, so you get a blank line. It is handy for spacing things out.
You can also give fmt.Println several strings. Put a comma between them and Go shows them on one line, with a space between each.
package main
import "fmt"
func main() {
fmt.Println("Ready")
fmt.Println("Steady")
fmt.Println()
fmt.Println("Go!")
} The commas go between the strings, outside the quote marks.
guess first
How will this look 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("Beans", "on", "toast")
}
your turn
Your turn. Write a knock knock joke.
Type who is at the door in the first two blanks, the same both times. Put your punchline in the last blank, then press run and enjoy your output.
output
press run to see what happens
fix it
The cheer will not run. Can you fix it?
output
press run to see what happens
- Go stopped before showing anything. Look at what sits between the strings.
- There should be a comma between each string inside the brackets.
- Add a comma after "Hip" and after "hip", then press run.
nailed it
you made the computer tell a joke. :D
- Lines run in order, from top to bottom.
- An empty
fmt.Println()makes a blank line. - Commas let one
fmt.Printlnshow several strings, with spaces between.
new words in your collection
- output
This lesson isn’t saved. A free account remembers every lesson you finish.