All challenges
ProgrammingWrite codeBeginner6 min
Ticket price
Skills: Control flow · Functions
Task
A museum charges by age. Write ticketPrice(age) so it returns:
- 5 for children under 12
- 7 for visitors aged 65 or older
- 10 for everyone else
A 12-year-old pays 10 and a 65-year-old pays 7.
Examples
Run examples tries these. Check solution also runs 5 more tests.
- A child pays 5Example
- Call
- ticketPrice(8)
- Expected
- Returns 5
- An adult pays 10Example
- Call
- ticketPrice(30)
- Expected
- Returns 10
Every test, including the extra ones, is part of this page. Nothing is hidden or secret.
Your code
Loading the editor…
function ticketPrice(age) {
// Return 5, 7 or 10.
}
Ctrl + Enter (⌘ + Enter on a Mac) runs the examples; add Shift to check. Tab indents; press Esc, then Tab, to leave the editor.
Run examples tries your code on the examples and records nothing. Check solution runs every test and saves an attempt.
Tests
Run your code to see which tests pass.
Console
What your code logs with console.log appears here.