Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LibraryCollection{
- constructor(capacity){
- this.capacity=capacity;
- this.books=[];
- }
- addBook (bookName, bookAuthor){
- if(this.books.length > this.capacity){
- throw Error('Not enough space in the collection.');
- }else{
- let book={
- bookName:bookName,
- bookAuthor:bookAuthor,
- payed: false,
- }
- this.books.push(book)
- return (`The ${bookName}, with an author ${bookAuthor}, collect.`)
- }
- }
- payBook( bookName ) {
- if(!this.books.some(x => x.bookName == bookName)){
- throw new Error(`${bookName} is not in the collection.`)
- }
- if (this.books.some(x => x.payed == true)) {
- throw new Error(`${bookName} has already been paid.`)
- }else{
- let book = this.books.some(x => x.bookName == bookName);
- this.book.payed = true;
- return `${bookName} has been successfully paid.`;
- }
- }
- removeBook(bookName) {
- if(!this.books.some(x => x.bookName == bookName)){
- throw new Error(`The book, you're looking for, is not found.`);
- }
- if (this.books.some(x => x.payed == false)) {
- throw new Error(`${bookName} need to be paid before removing from the collection.`);
- }else{
- this.books=this.books.filter(x => x.bookName != bookName);
- return `${bookName} remove from the collection.`;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment