Commit 7b08a1ce authored by David Garner's avatar David Garner
Browse files

added button to checkout books

parent 712f157f
......@@ -13,7 +13,7 @@
}
table, tr, td {
border-collapse: collapse;
border-jlapse: jlapse;
border-style: solid;
border-width: 1px;
padding: 4px;
......@@ -23,8 +23,11 @@
background: #e8fcea;
padding: 6px;
}
</style>
</head>
<body>
</body>
</html>
\ No newline at end of file
......@@ -8,41 +8,47 @@ var Library = function(name) {
this.shelves = [];
};
Library.prototype.addShelf = function() {
this.shelves.push(new Shelf());
Library.prototype.addShelf = function(shelfName) {
this.shelves.push(new Shelf(shelfName));
};
Libary.prototype.checkOutBook = function(title){
for (var i =0;i < this.books.length; i++) {
Library.prototype.checkOutBook = function(title){
for (var i =0;i < this.shelves.length; i++) {
var book = this.books[i];
if(book.title == title){
if(book.checkIn){
book.numCopies--;
if(book.numCopies <= 0){
book.isCheckedOut = true;
var shelf = this.shelves[i];
for(var j=0; j<shelf.books.length; j++){
var book = shelf.books[j];
if(book.name == title){
if(!book.isCheckedOut){
book.numCopies--;
if(book.numCopies <= 0){
book.isCheckedOut = true;
}
console.log(title + " has been checkedOut");
}
return book;
}
//console.log(title + " has been checkedOut");
}
};
}
}
var Shelf = function() {
var Shelf = function(myName) {
this.books = [];
this.name = myName
};
Shelf.prototype.addBook = function(book){
this.books.push(book);
Shelf.prototype.addBook = function(title){
this.books.push(new Book(title));
};
var Book = function(name) {
this.name = name;
this.isCheckedOut = false;
this.numCopies = 1;
this.numCopies = 5;
};
......@@ -51,7 +57,5 @@ Book.prototype.checkedOut = function(){
this.isCheckedOut = false;
};
Book.prototype.checkIn = function (){
this.isCheckedOut = true;
};
......@@ -5,7 +5,7 @@
jQuery(function () {
// CSS
$("body").css('background', 'green');
$("h1").css('color', 'white');
$("h1").css('jor', 'white');
$("p").css('font-size', '20px');
$("button").css('height', '20px');
$("a").css('text-decoration', 'none');
......
......@@ -7,37 +7,60 @@ jQuery(function() {
lib = new Library("Iowa State Library");
i = 0;
while (i < 3) {
lib.addShelf(new Shelf("Shelf" + i));
lib.addShelf("Shelf" + i);
j = 0;
while (j < 10) {
lib.shelves[i].addBook(new Book("Book" + j));
lib.shelves[i].addBook("Book" + j);
j++;
}
i++;
}
var myTitle = "here";
table = "";
table += "<h1>";
table += lib.name;
table += "</h1>";
table += "<table>";
for(i = 0; i < lib.shelves.length; i++) {
table += "<tr>";
currentShelf = lib.shelves[i];
table +="<th>";
table += "Shelf" + i;
table += "</th>";
for(j = 0; j < currentShelf.books.length; j++) {
currentBook = currentShelf.books[j];
table += "<td>";
table += currentBook.name;
table += "</td>";
}
table += "</tr>"
}
table += "<table id='myTable'>";
table += "</table>";
$('body').append(table);
$('body').append("<button>Sumbit</button>")
$(function(){
$('button').on('click',function(){
lib.checkOutBook("Book1");
});
});
var table = document.getElementById('myTable');
var topRow = table.insertRow(-1);
for (var i = 0; i < lib.shelves.length; i++) {
currentShelf = lib.shelves[i];
topRow.insertCell(-1).innerHTML = currentShelf.name
for (var j = 1; j < currentShelf.books.length; j++) {
if(i == 0){
table.insertRow(-1);
}
currentBook = currentShelf.books[j];
table.rows[j].insertCell(-1).innerHTML = currentBook.name;
}
}
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment