Skip to content

Commit

Permalink
implemented basic features
Browse files Browse the repository at this point in the history
  • Loading branch information
Tushar-Manna committed Oct 21, 2024
1 parent e6027c4 commit 85168d9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 118 deletions.
36 changes: 36 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<table id="myTable" border="1">
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Pages</th>
<th>Read</th>
</tr>
</thead>
<tbody>
</tbody>
</table>


<form onsubmit="handleSubmit(event)" id="bookForm">
<input type="text" id="title">
<input type="text" id="author">
<input type="text" id="pages">
<input type="text" id="read">
<input type="submit">
</form>



<script src="script.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

const myLibrary = [];

function Book(title, author, pages, read) {
this.title = title;
this.author=author;
this.pages= pages;
this.read=read;
}


function addBook(title, author, pages, read) {
myLibrary.push(new Book(title, author, pages, read))
}

function removeBook(index) {
myLibrary.splice(index,1)
renderLibrary()
}

function handleSubmit(event) {
event.preventDefault();
const title = document.getElementById('title').value ;
const author = document.getElementById('author').value ;
const pages = document.getElementById('pages').value ;
const read = document.getElementById('read').value ;

if (!title || !author || !pages || !read) {
alert("all fields much be filled out.");
return;
}

addBook(title, author, pages, read);
renderLibrary()
document.getElementById('bookForm').reset();
}



console.log(myLibrary);

function renderLibrary() {
document.querySelector('#myTable tbody').innerHTML = myLibrary.map((book, index) => `<tr>
<td>${book.title}</td>
<td>${book.author}</td>
<td>${book.pages}</td>
<td>${book.read}</td>
<td><button onclick="removeBook(${index})">Remove</button></td>
</tr>`
).join('')
}
118 changes: 0 additions & 118 deletions test.js

This file was deleted.

0 comments on commit 85168d9

Please sign in to comment.