Menu
Coddy logo textTech

הוספת הקרנה

חלק מהיחידה לוגיקה וזרימת התוכנית במסלול ה-JavaScript של Coddy. שיעור 62 מתוך 65.

challenge icon

אתגר

קל

הוסיפו מקרה בדיקה חדש להצהרת ה־switch שלכם: addScreening.

עבור addScreening, פרמטרי הנתונים מכילים:

  • movieId (מספר)
  • venueId (מספר)
  • date (מחרוזת בפורמט 'YYYY-MM-DD')
  • time (מחרוזת בפורמט 'HH:MM:SS')

הפונקציה צריכה:

  1. לוודא שסרט עם movieId הנתון ואולם עם venueId הנתון קיימים ב־festivalData. אם אחד מהם לא נמצא, הוסיפו את "Movie or venue not found!" לתוצאות
  2. לבדוק שאין הקרנה באותו אולם, בתאריך ובשעה האלה — אם קיימת הקרנה, הוסיפו את "Screening already exists at this time!" לתוצאות
  3. ליצור אובייקט הקרנה חדש עם:
    • id: ליצור על ידי הוספת 1 לאורך מערך ההקרנות
    • movieId, venueId, date ו־time מתוך הנתונים
    • availableSeats: שווה לקיבולת האולם
  4. להוסיף את ההקרנה למערך festivalData.screenings
  5. להוסיף את 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;
}

כל השיעורים ביחידה לוגיקה וזרימת התוכנית

תרגלו בעצמכם: קומפיילר JavaScript אונליין