映画と会場の追加
CoddyのJavaScriptジャーニー「論理とフロー」セクションの一部。レッスン 61/65。
チャレンジ
簡単switch 文に新しいケースを 2 つ追加します:addMovie と addVenue。
addMovie の場合、data パラメーターには次の内容が含まれます:
- title(文字列)
- director(文字列)
- year(数値)
- mainGenre(文字列)
- secondGenre(文字列)
この関数は次の処理を行う必要があります:
- 次の内容を持つ新しい映画オブジェクトを作成する:
- id: movies 配列の長さに 1 を加えて生成
- data の title、director、year、mainGenre、secondGenre
- avgRating: 0
- available: true
- 映画を
festivalData.movies配列に追加する Movie added successfully!をresults配列に追加する
addVenue の場合、data パラメーターには次の内容が含まれます:
- name(文字列)
- capacity(数値)
この関数は次の処理を行う必要があります:
- 次の内容を持つ新しい会場オブジェクトを作成する:
- id: venues 配列の長さに 1 を加えて生成
- data の
nameとcapacity
- 会場を
festivalData.venues配列に追加する Venue added successfully!をresults配列に追加する
自分で試してみよう
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;
}論理とフローのすべてのレッスン
自分で練習してみよう: JavaScriptオンラインコンパイラ