ticketPrice

Easy · Conditionals · 5 test cases

Calculate the price of a movie ticket based on age. The prices are: Child (age <= 12) is $10, Adult (age 13-59) is $15, and Senior (age >= 60) is $12.

Examples

ticketPrice(10) → 10
ticketPrice(30) → 15
ticketPrice(65) → 12

Starter code

function ticketPrice(age) {

}

Complexity of the optimal solution

Time O(1), space O(1). This function involves a small, fixed number of conditional checks. Therefore, it runs in constant time.

Solve ticketPrice in the browser