Kodewick
Start learning →
Mini challenge←→0 / 70

Movie rating

#017Mini challengeConditionsStrings6 min

The cinema checks the rating: "G" is for everyone; "PG-13" needs age 13 or more, or a parent along (withParent); "18" needs age 18 or more, parent or not. Write CanWatch(age, rating, withParent) to return true if they may watch. The rating is always one of these three.

Examples
CanWatch(8, "G", false)→True
CanWatch(10, "PG-13", true)→True
CanWatch(16, "18", true)→False
The functionfunc CanWatch(age int, rating string, withParent bool) bool
main.go
package main

func CanWatch(age int, rating string, withParent bool) bool {
	if rating == "G" {
		return true
	}
	// your code here: one if each for "PG-13" and "18"; return true when allowed
	return false
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.