-
Notifications
You must be signed in to change notification settings - Fork 0
/
#1 Organizer(not complete).js
54 lines (52 loc) · 1.77 KB
/
#1 Organizer(not complete).js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//create a program that will allow you to enter events organizable by hour. There must be menu options of some form, and you must be able to easily edit, add, and delete events without directly changing the source code.
Event = function(name, time) {
var eventName = name,
eventTime = time;
this.getInfo = function(){
return { name:eventName,time:eventTime};
};
this.changeName = function(name){
eventName = name;
};
this.changeTime = function(time){
eventTime = time;
};
};
Calander = function(){
var eventsList= [];
this.editEvent= function() {
var event = prompt('What event would you like to delete?');
for(i=0;i<eventsList.length;i++){
if(eventsList[i].getInfo().name === event){
eventsList[i].changeName(prompt('Please rename the event?'));
eventsList[i].changeTime(prompt('Please set the time'));
return;
}
}v
};
this.addEvent= function() {
var time = prompt('Please input the event time');
var name = prompt('Please input the event name');
eventsList.push(new Event(name,time));
};
this.deleteEvent= function() {
var event = prompt('What event would you like to delete?');
for(i=0;i<eventsList.length;i++){
if(eventsList[i].getInfo().name === event){
eventsList.splice(i,1);
return;
}
}
};
this.showEvents= function(){
for(i=0;i<eventsList.length;i++){
event = eventsList[i].getInfo();
console.log('Event: '+event.name+', Time: '+event.time);
}
}
};
calander = new Calander();
calander.addEvent();
calander.showEvents();
calander.editEvent();
calander.showEvents();