Course / The terminal and the language
Can they ride?
How to fetch and submit this lab
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach 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 submitGoal
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.CanRidehas a// TODOcomment and a return line you will change. - If
Bannedistrue, returnfalseimmediately, regardless of anything else. - Otherwise, return
trueifAgeis10or more andHeightis120or more. - Otherwise, also return
trueifWithAdultistrueandHeightis100or more. - Otherwise, return
false. - Do not change the
vardeclarations or theCanRidefunction 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
- A banned rider is refused no matter what else is true — check that one first and return false immediately.
- 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 ||.
- if Banned { return false } return (Age >= 10 && Height >= 120) || (WithAdult && Height >= 100)