Skip to content

Commit fbcd381

Browse files
Classes exercises completed
1 parent 7009f99 commit fbcd381

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

classes/exercises/ClassExercises.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
1-
// Define your Book class here:
1+
class Book {
2+
constructor(title, author, copyright, isbn, pages, timesCheckedOut, discarded) {
3+
this.title = title;
4+
this.author = author;
5+
this.copyright = copyright;
6+
this.isbn = isbn;
7+
this.pages = pages;
8+
this.timesCheckedOut = timesCheckedOut;
9+
this.discarded = discarded;
10+
}
211

12+
checkout(uses = 1) {
13+
this.timesCheckedOut += uses;
14+
}
15+
}
316

4-
// Define your Manual and Novel classes here:
17+
class Manual extends Book {
18+
constructor(title, author, copyright, isbn, pages, timesCheckedOut, discarded) {
19+
super(title, author, copyright, isbn, pages, timesCheckedOut, discarded);
20+
}
521

22+
dispose(currentYear) {
23+
if (currentYear - this.copyright > 5) {
24+
this.discarded = 'Yes';
25+
}
26+
}
27+
}
628

7-
// Declare the objects for exercises 2 and 3 here:
29+
let funReading = new Manual('Pride and Prejudice', 'Jane Austen', 1813, '1111111111111', 432, 32, 'No');
830

31+
class Novel extends Book {
32+
constructor(title, author, copyright, isbn, pages, timesCheckedOut, discarded) {
33+
super(title, author, copyright, isbn, pages, timesCheckedOut, discarded);
34+
}
935

10-
// Code exercises 4 & 5 here:
36+
dispose() {
37+
if (this.timesCheckedOut > 100) {
38+
this.discarded = 'Yes';
39+
}
40+
}
41+
}
42+
43+
44+
let makingTheShip = new Manual('Top Secret Shuttle Building Manual', 'Redacted', 2013, '0000000000000', 1147, 1, 'No');
45+
46+
// Code exercises 4 & 5 here:
47+
funReading.dispose(2024);
48+
makingTheShip.checkout(5);
49+
console.log(funReading);
50+
console.log(makingTheShip);

0 commit comments

Comments
 (0)