JSFiddle - React, Tailwind, and code Playground

by Fareez Ahmed

JavaScript

//Library Constructor
// Model a library using objects. *
// A library contains shelves. Shelves contain books. 
// Books have an author and a title. Give the library methods to add and remove a shelf. 
// A shelf should have methods to add/remove a book. Use a modular approach so that each type of object is contained in its own file. 


// The thing that you need to do with the add and remove shelves that will also make it
//  work automatically is that the shelf you add needs to be an instance of the Shelf object you define.
// If you clean up some of your abstractions the code should be much easier to 
// organize and how things should be connected will be much cleaner. For example 
// a library only needs to be able to add and remove shelves. A shelf only needs 
// to be able to add and remove books. And a book only needs to exist. This way, 
// once you create a book and put it on a shelf and then put that shelf in a library 
// you’ve added the book to the library by association.



var Library = function(n) {
	this.name = n;
	this.numOfShelves = 0;
	this.books = [];

	this.addShelf = new Shelf(n,l);
	
	this.removeShelf = function(n, l){
		this.name = n;
		l.numOfShelves--;
		console.log("A shelf called " + shlf + " has been removed from " + l.name + ". ");

	};};
	
	// this.reportBooks = function(){
	// 	console.log("Here are all the books contained in " + this.name + ": ");
	// 	for(i=0; i<this.books.length; i++){
	// 		console.log(this.books[i]);
	// 	};
	// };
	
	// this.reportShelves = function(){
	// 	console.log("Here are all the shelves contained in " + this.name + ": ");
	// 	for(i=0; i<this.numOfShelves.length; i++){
	// 		console.log(this.numOfShelves[i]); //this seem right?
	// 	};

	// };

	// console.log("A new library called " + this.name + " has been created.");

}

//Shelf Constructor
var Shelf = function(n, l){
	this.name = n;
	this.numOfBooks = 0;
	this.booksOnShelf = [];
	l.numOfShelves++;
	console.log("A new shelf called " + n + " has...