×

go · level 1 · unit 4 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Build bigger questions with , and .

&& means and. It gives true only when both sides are true. A cake needs flour and eggs: if either one is missing, there is no cake.

|| means or. It gives true when at least one side is true, like a lie-in on Saturday or Sunday. ! means not and flips an answer, so !true is false.

A bool box already counts as a condition. So if !hasEggs { reads like plain English: if we do not have eggs.

package main
import "fmt"
func main() {
	hasFlour := true
	hasEggs := false
	if hasFlour && hasEggs {
		fmt.Println("Time to bake a cake!")
	}
	if !hasEggs {
		fmt.Println("Off to the shop for eggs.")
	}
}

Write a full condition on each side, like day == "Saturday" || day == "Sunday".