go · level 1 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A box can hold something new.
Boxes can change. mood = "awake" takes the old value out of mood and puts the new one in. This is called assigning. Use := once, to make the box. After that, plain = does the job.
You can copy one box into another, like best = mood. You can also strings with +: "fish" + "cake" makes "fishcake". Add your own spaces, because + never adds any.
package main
import "fmt"
func main() {
mood := "sleepy"
fmt.Println("I feel", mood)
mood = "awake"
fmt.Println("Now I feel", mood)
greeting := "Good" + " morning"
fmt.Println(greeting)
} A box holds one value at a time, so the old one is gone for good.
guess first
Two new boxes with one name? Guess first.
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
package main
import "fmt"
func main() {
drink := "tea"
drink := "coffee"
fmt.Println(drink)
}
your turn
Your turn. Build a full name.
Type a first name and a last name in the two boxes. Line 6 joins them with a space in the middle. Press run to meet them.
output
press run to see what happens
fix it
The birthday message is squashed. Fix it!
output
press run to see what happens
- Run it and look closely at the output. What is missing after the comma?
+sticks strings together exactly as they are. It never adds a space for you.- Put a space after the comma, inside the quotes: "Happy birthday, ". Then press run.
nailed it
your boxes can change their minds. :D
:=makes a new box.=changes one that exists.- A box holds one value at a time.
+joins strings, but never adds spaces.
new words in your collection
- assign
- join
This lesson isn’t saved. A free account remembers every lesson you finish.