From 85168d9aacf51e35b907ca4ed4a1785db99ca5ac Mon Sep 17 00:00:00 2001 From: Tushar Manna Date: Mon, 21 Oct 2024 19:27:38 +0530 Subject: [PATCH] implemented basic features --- index.html | 36 ++++++++++++++++ script.js | 51 +++++++++++++++++++++++ test.js | 118 ----------------------------------------------------- 3 files changed, 87 insertions(+), 118 deletions(-) create mode 100644 index.html create mode 100644 script.js delete mode 100644 test.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..8ef3737 --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + + + + + Document + + + + + + + + + + + + + + +
TitleAuthorPagesRead
+ + +
+ + + + + +
+ + + + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..70467b3 --- /dev/null +++ b/script.js @@ -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) => ` + ${book.title} + ${book.author} + ${book.pages} + ${book.read} + + ` +).join('') +} \ No newline at end of file diff --git a/test.js b/test.js deleted file mode 100644 index 48bd5cb..0000000 --- a/test.js +++ /dev/null @@ -1,118 +0,0 @@ -const myobject = { - property1 : "value", - property2 : 77, - "obnoxious property" : () => { - console.log("ayo chill") - } -} - - - -//there are two types of object retrieval procedure - - -//dot notation -myobject.property1; - -//bracket notation -myobject["obnoxious property"]; - -//even though dot notation is clearer but sometimes we -//must need to use bracket notation because string can't be used -//with bracket notation - -const v = "property"; - -//variable can be used directly with bracket notation -myobject[v]; //this is valid - - -//creating a basic object -const player1 = { - name: "Tushar", - age : 21 -} - -const player2 = { - name: "Koushik", - age: 18 -} - -//takes the player as param and then constructs it as a object reference -function printname(player) { - console.log(player.name) -} - -printname(player1) - -//I just realised I could have made the whole object at once - -const players = { - player1: { - name: "Tushar", - age: 21 - }, - player2: { - name: "koushik", - age: 18 - } -} - -console.log (players.player1.name) - -//or I can do this -//I could use the param to make a dot notation because I was passing the full object -//but in this case I am passing string -function print1(playerkey) { - console.log(players[playerkey].name) -} - -// Still I need to take a deeper look into it - -print1("player1") - -console.log("New notes") -//new codes - - -// this is called object constructor or something like this I guess -function Player (name, marker) { - this.name = name; - this.marker = marker; -} - -// then it can be called by using the new keyword -const player = new Player('steve', 'x'); -console.log(player.name) - -console.log("..........................") -//exercise - -function Book (title, author, nop, read ) { - this.title = title; - this.author = author; - this.nop = nop; - this.read = read; - this.info = () => { - return ( - `title = ${this.title} \n - author = ${this.author}\n - number of pages = ${this.nop}\n - read = ${this.read}` - ) - - } -} - - - -const bestBook = new Book ("the best of ruskin bond", "ruskin bond", "400", "partially") - -console.log(bestBook.info()); - -// - -console.log(Object.getPrototypeOf(Player.prototype) === Object.prototype); - -//test -//test2 \ No newline at end of file