forked from truecodersio/JavaScript_OOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotebook.js
More file actions
54 lines (45 loc) · 1.09 KB
/
Notebook.js
File metadata and controls
54 lines (45 loc) · 1.09 KB
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
console.log("Script attached");
class Notebook {
constructor(propertyOf) {
this.length = 0;
this.propertyOf = propertyOf;
this.subject = subject;
this.nextId = 1;
this.notes = [];
}
add(note) {
note.id = this.nextId++;
this.entries.push(note);
}
delete(noteId) {
this.entries = this.entries.filter(function(entry) {
if (entry.id == noteId) {
return false;
else return true;
}
});
}
read(noteId) {
let note = this.entries.find(function(n) {
if (n.id == noteId) return true;
else return false;
});
alert(note.content);
}
}
class Note {
constructor(title, content) {
this.id = null;
this.title = title;
this.content = content;
}
}
let notebook = new NoteBook("Tanner Voss");
let newNoteTitle = prompt("Title:", "New Note");
let newNote = prompt("Note:");
if (newNote) {
notebook.add(new Note(newNote));
}
notebook.read(1);
notebook.delete(1);
console.log(notebook);