Skip to content

Commit

Permalink
Classes exercise done
Browse files Browse the repository at this point in the history
  • Loading branch information
craigb28 committed Feb 15, 2024
1 parent fdfc8a4 commit 4359146
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion classes/exercises/ClassExercises.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,99 @@
// Define your Book class here:

class Book {
constructor(
title,
author,
copyright,
isbn,
pages,
timesCheckedOut,
discarded
) {
this.title = title;
this.author = author;
this.copyright = copyright;
this.isbn = isbn;
this.pages = pages;
this.timesCheckedOut = timesCheckedOut;
this.discarded = discarded;
}

checkout(uses = 1) {
this.timesCheckedOut += uses;
}
}

// Define your Manual and Novel classes here:

class Manual extends Book {
constructor(
title,
author,
copyright,
isbn,
pages,
timesCheckedOut,
discarded
) {
super(title, author, copyright, isbn, pages, timesCheckedOut, discarded);
}
dispose(currentYear) {
if (currentYear - this.copyright > 5) {
this.discarded = "Yes";
}
}
}

class Novel extends Book {
constructor(
title,
author,
copyright,
isbn,
pages,
timesCheckedOut,
discarded
) {
super(title, author, copyright, isbn, pages, timesCheckedOut, discarded);
}
dispose() {
if (this.timesCheckedOut > 100) {
this.discarded = "Yes";
}
}
}

// Declare the objects for exercises 2 and 3 here:

let prideAndPrejudice = new Novel(
"Pride and Prejudice",
"Jane Austen",
1813,
"1111111111111",
432,
32,
"No"
);

let topSecretShuttleBuildingManual = new Manual(
"Top Secret Shuttle Building Manual",
"Redacted",
2013,
"0000000000000",
1147,
1,
"No"
);



// Code exercises 4 & 5 here:

topSecretShuttleBuildingManual.dispose(2024);

prideAndPrejudice.checkout(5);
prideAndPrejudice.dispose();

// Code exercises 4 & 5 here:
console.log(prideAndPrejudice);
console.log(topSecretShuttleBuildingManual);

0 comments on commit 4359146

Please sign in to comment.