538.Decide Entry Using Logical Operators
Easy
A cinema lets someone in when they have a ticket and either are at least 18 or come with an adult. Given
age, hasTicket and withAdult, return whether they may enter.
Logical operatorsLogical OperatorsAND (&&, and), OR (||, or) and NOT (!, not) — they combine true/false values into one true/false result. let one condition express a whole rule. The first solution spells the rule out with separate if checks; the second writes it as a single expression. Both rely on short-circuit evaluationShort-Circuit EvaluationAND stops at the first false operand and OR stops at the first true one, because the final answer is already decided.: once the answer is known, the remaining checks are skipped.
Example 1:
Input: age = 15, hasTicket = true, withAdult = true
Output: true
Example 2:
Input: age = 30, hasTicket = false, withAdult = true
Output: false
+ 6 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ age ≤ 120
age =
15
hasTicket =
true
withAdult =
true