Menu
Coddy logo textTech

Project Overview

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

challenge icon

Challenge

Easy

You will be creating a Movie Festival Management System. Start by initializing the system with the provided data and creating the main function structure.

Create a variable called festivalData with this exact initial data:

{
	movies: [{
		id: 1,
		title: "Inception",
		director: "Christopher Nolan",
		year: 2010,
		mainGenre: "Sci-Fi",
		secondGenre: undefined,
		avgRating: 0,
		available: true
	}],
	venues: [{
		id: 1,
		name: "Main Theater",
		capacity: 200,
	}],
	screenings: [{
		id: 1,
		movieId: 1,
		venueId: 1,
		date: '2023-10-29',
		time: '13:35:00',
		availableSeats: 200
	}],
	tickets: new Set()
}

Create a function called manageFestival that takes two parameters:

  • actions (array of strings)
  • data (array of objects)

The function should:

  1. Process each action in the actions array in sequence
  2. Create an empty results array
  3. Create a switch statement with the following initial cases:
    • listMovies: adds festivalData.movies to results array
    • listVenues: adds festivalData.venues to results array
    • listTickets: adds festivalData.tickets to the results array
    • listScreenings: adds festivalData.screenings to the results array
    • default: adds "Invalid action!" to results array
  4. Return the results array

Try it yourself


const festivalData = {}; // Fill initial data

function manageFestival(actions, data) {
    let results = [];
    
    actions.forEach((action, index) => {
        const currentData = data[index];
        
        switch(action) {
            case "listMovies":
               // Write your code here

            case "listVenues":
               // Write your code here

            case "listTickets":
                // Write your code here

            case "listScreenings":
                // Write your code here
                
            default:
                results.push("Invalid action!");
        }
    });
    
    return results;
}

All lessons in Logic & Flow