Menu
Coddy logo textTech

상영 일정 추가하기

Coddy JavaScript 여정의 논리 & 흐름 섹션에 포함된 레슨 — 65개 중 62번째.

challenge icon

챌린지

쉬움

switch 문에 새로운 테스트 케이스인 addScreening을 추가하세요.

addScreening의 경우 데이터 매개변수에는 다음이 포함됩니다:

  • movieId (숫자)
  • venueId (숫자)
  • date ('YYYY-MM-DD' 형식의 문자열)
  • time ('HH:MM:SS' 형식의 문자열)

함수는 다음을 수행해야 합니다:

  1. 영화와 장소가 존재하는지 확인합니다. 영화나 장소를 찾을 수 없는 경우, results에 "Movie or venue not found!"를 추가합니다.
  2. 동일한 장소, 날짜 및 시간에 상영이 없는지 확인합니다. 상영이 이미 존재하는 경우, results에 "Screening already exists at this time!"을 추가합니다.
  3. 다음 속성을 가진 새로운 상영 객체를 생성합니다:
    • id: 상영 배열의 길이에 1을 더하여 생성
    • 데이터로부터 받은 movieId, venueId, date, time
    • availableSeats: 장소의 수용 인원(capacity)과 동일하게 설정
  4. 상영 객체를 festivalData.screenings 배열에 추가합니다.
  5. results 배열에 Screening added successfully!를 추가합니다.

직접 해보기

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;

            case "addMovie":
                const newMovie = {
                    id: festivalData.movies.length + 1,
                    title: currentData.title,
                    director: currentData.director,
                    year: currentData.year,
                    mainGenre: currentData.mainGenre,
                    secondGenre: currentData.secondGenre,
                    avgRating: 0,
                    available: true
                };
                festivalData.movies.push(newMovie);
                results.push("Movie added successfully!");
                break;

            case "addVenue":
                const newVenue = {
                    id: festivalData.venues.length + 1,
                    name: currentData.name,
                    capacity: currentData.capacity,
                };
                festivalData.venues.push(newVenue);
                results.push("Venue added successfully!");
                break;


            default:
                results.push("Invalid action!");
        }
    });
    
    return results;
}

논리 & 흐름의 모든 레슨