go · level 1 · unit 2 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A good name tells you what is in the box.
A name can use letters, digits and the underscore _. It cannot contain spaces, and it cannot start with a digit: pet2 is fine, 2pets is not. Case matters, so pet and Pet are two different boxes.
Some words are taken. A such as func, var or import already means something to Go, so it cannot be a name.
Pick names that say what is inside: score beats s. When a name needs several words, Go uses , like petName or bestFriend. Each new word starts with a capital, like the humps on a camel.
package main
import "fmt"
func main() {
petName := "Biscuit"
favouriteFood := "pizza"
pet2 := "Pickles"
fmt.Println(petName, favouriteFood, pet2)
} Go does not care what a name means, only that you spell it the same way every time.
guess first
Same name, different capitals. What happens?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
package main
import "fmt"
func main() {
petName := "Biscuit"
PetName := "Pickles"
fmt.Println(PetName, petName)
}
your turn
Your turn. Name a box in camelCase.
Name the box in camelCase, such as bestFriend, and use exactly the same name in both name blanks. Put your friend's name between the quotes.
output
press run to see what happens
fix it
This name has a gap in it. Can you fix it?
output
press run to see what happens
- Go reads a space as the end of a name. How many names does Go see on line 4?
- A name cannot contain a space. Join the two words into one name.
- Use camelCase: change winner name to winnerName on both lines, then press run.
nailed it
you picked names go understands. :D
- Names use letters, digits and
_, with no spaces. - A name cannot start with a digit or be a keyword.
- Go uses camelCase for longer names, like
petName.
new words in your collection
- keyword
- camelCase
This lesson isn’t saved. A free account remembers every lesson you finish.