-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// webinars.js | ||
|
||
class Webinars { | ||
constructor() { | ||
this.webinarList = []; // Store educational webinars | ||
} | ||
|
||
// Create a new webinar | ||
createWebinar(title, description, date, duration, presenter) { | ||
const webinar = { | ||
id: this.webinarList.length + 1, | ||
title, | ||
description, | ||
date, | ||
duration, | ||
presenter, | ||
attendees: [], | ||
}; | ||
this.webinarList.push(webinar); | ||
console.log(`Webinar created:`, webinar); | ||
return webinar; | ||
} | ||
|
||
// Get all webinars | ||
getAllWebinars() { | ||
return this.webinarList; | ||
} | ||
|
||
// Register a user for a webinar | ||
registerForWebinar(webinarId, userId) { | ||
const webinar = this.webinarList.find(w => w.id === webinarId); | ||
if (webinar) { | ||
if (!webinar.attendees.includes(userId)) { | ||
webinar.attendees.push(userId); | ||
console.log(`User ${userId} registered for webinar:`, webinar.title); | ||
return webinar; | ||
} else { | ||
throw new Error('User is already registered for this webinar.'); | ||
} | ||
} else { | ||
throw new Error('Webinar not found.'); | ||
} | ||
} | ||
|
||
// Get attendees for a webinar | ||
getWebinarAttendees(webinarId) { | ||
const webinar = this.webinarList.find(w => w.id === webinarId); | ||
if (webinar) { | ||
return webinar.attendees; | ||
} else { | ||
throw new Error('Webinar not found.'); | ||
} | ||
} | ||
} | ||
|
||
// Example usage | ||
const webinarsManager = new Webinars(); | ||
const newWebinar = webinarsManager.createWebinar( | ||
'Understanding Financial Literacy', | ||
'Join us for an informative session on financial literacy basics.', | ||
'2023-10-20', | ||
'1 hour', | ||
'Jane Doe' | ||
); | ||
webinarsManager.createWebinar( | ||
'Investing 101', | ||
'Learn the fundamentals of investing and how to get started.', | ||
'2023-11-05', | ||
'1.5 hours', | ||
'John Smith' | ||
); | ||
|
||
const allWebinars = webinarsManager.getAllWebinars(); | ||
console.log('All Educational Webinars:', allWebinars); | ||
|
||
webinarsManager.registerForWebinar(newWebinar.id, 'user123'); | ||
const attendees = webinarsManager.getWebinarAttendees(newWebinar.id); | ||
console.log('Attendees for webinar:', attendees); | ||
|
||
export default Webinars; |