Menu
Coddy logo textTech

Recap - Simple Logic

Part of the Fundamentals section of Coddy's Swift journey — lesson 23 of 86.

challenge icon

Challenge

Easy
Write a function canRideRollercoaster that takes height and hasParent and returns whether a person can ride the rollercoaster.

A person can ride the rollercoaster if they meet the height requirement AND are accompanied by a parent, OR if they are tall enough to ride alone.

Conditions:

  • If height is at least 140 cm, they can ride alone (no parent needed)
  • If height is at least 120 cm but less than 140 cm, they need a parent to ride
  • If height is less than 120 cm, they cannot ride at all

Parameters:

  • height (Int): The person's height in centimeters
  • hasParent (Bool): Whether a parent is accompanying them

Returns: true if the person can ride, false otherwise (Bool)

Try it yourself

func canRideRollercoaster(height: Int, hasParent: Bool) -> Bool {
    // Write code here
}

All lessons in Fundamentals