Fix the Ticket Message
JavaScript
10 pts
Fix the Ticket Message
The function ticketMessage(age) in the starter crashes with ReferenceError: message is not defined. The variable message is created inside the if and else blocks, so it does not exist on the return line.
Fix the scope: declare message once, inside the function but before the if, and only assign it in the two blocks. Do not make it a global variable. The output must be:
Child ticket: 10 Nakfa Adult ticket: 25 Nakfa
Children are younger than 12.
Checklist
- The function returns the right message for children and adults.
- Declare
messageonce, at function level (not global, not in the blocks). - The two lines are printed.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
