Menu
Coddy logo textTech

Add Movies & Venues

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

challenge icon

Challenge

Easy

Add two new cases to your switch statement: addMovie and addVenue.

For addMovie, the data parameter contains:

  • title (string)
  • director (string)
  • year (number)
  • mainGenre (string)
  • secondGenre (string)

The function should:

  1. Create a new movie object with:
    • id: generate by adding 1 to the length of movies array
    • title, director, year, and mainGenre, secondGenre from the data
    • avgRating: 0
    • available: true
  2. Add the movie to festivalData.movies array
  3. Add Movie added successfully! to results array

For addVenue, the data parameter contains:

  • name (string)
  • capacity (number)

The function should:

  1. Create a new venue object with:
    • id: generate by adding 1 to the length of venues array
    • name and capacity from the data
  2. Add the venue to festivalData.venues array
  3. Add Venue added successfully! to results array

Try it yourself

const festivalData = {
	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()
}

function manageFestival(actions, data) {
    let results = [];
    
    actions.forEach((action, index) => {
        const currentData = data[index];
        
        switch(action) {
            case "listMovies":
                results.push(festivalData.movies);
                break;
                
            case "listVenues":
                results.push(festivalData.venues);
                break;

            case "listTickets":
                results.push(festivalData.tickets);
                break;

            case "listScreenings":
                results.push(festivalData.screenings);
                break;
                
            default:
                results.push("Invalid action!");
        }
    });
    
    return results;
}

All lessons in Logic & Flow