Course outline
Course / The terminal and the language

Can they ride?

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each lab: download it, edit the file named in the instructions, then submit.

gonomicon fetch week-1/10-03-can-ride
cd 10-03-can-ride
gonomicon submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal Decide whether a rider can go on a ride by combining four package-level variables with &&, ||, and a guard for the banned case.

Example If a nightclub needed similar logic — never let in anyone banned, then require either being 21 with ID or being with a member and at least 18 — you'd write:

func CanEnter() bool {
	if Banned {
		return false
	}
	return (Age >= 21 && HasID) || (WithMember && Age >= 18)
}

Rules

  • Edit ride.go. CanRide has a // TODO comment and a return line you will change.
  • If Banned is true, return false immediately, regardless of anything else.
  • Otherwise, return true if Age is 10 or more and Height is 120 or more.
  • Otherwise, also return true if WithAdult is true and Height is 100 or more.
  • Otherwise, return false.
  • Do not change the var declarations or the CanRide function signature. Do not add imports.

What you'll practice Combining comparisons with && and ||, and using an early-return guard to handle the one condition that overrides everything else.

Run it

gonomicon fetch week-1/10-03-can-ride
cd 10-03-can-ride
gonomicon test
gonomicon submit

Hints

  1. A banned rider is refused no matter what else is true — check that one first and return false immediately.
  2. After the banned check, there are two separate ways in: old enough and tall enough, OR with an adult and tall enough. Combine each pair with && and join the two pairs with ||.
  3. if Banned { return false } return (Age >= 10 && Height >= 120) || (WithAdult && Height >= 100)

Something wrong with this lesson? Report a problem