Menu
Coddy logo textTech

Buy Tickets

Part of the Logic & Flow section of Coddy's JavaScript journey — lesson 63 of 65.

challenge icon

Challenge

Easy

Add case buyTicket that handles ticket purchases. The data parameter contains:

  • screeningId (number)
  • quantity (number)

The function should:

  1. Check if screening exists and has enough available seats
    • If not found, add Screening not found! to results array
    • If not enough seats, add Not enough seats available! to results array
  2. Create ticket IDs following this exact format:
    • For each ticket, create ID as: ${screeningId}-${currentAvailableSeats}
    • Example: If screeningId is 1 and availableSeats is 200, and quantity is 2:
      • First ticket ID will be "1-200"
      • Second ticket ID will be "1-199"
  3. Add each ticket ID to festivalData.tickets Set
  4. Subtract quantity from screening's availableSeats
  5. Add Tickets purchased successfully! to results array

Try it yourself

// Don't remove the lines below
const util = require('util');
util.inspect.defaultOptions.maxArrayLength = null;
// ---------------------------

All lessons in Logic & Flow