Skip to content

Javascript#1

Open
Krishan-Mishra wants to merge 4 commits into
mainfrom
javascript
Open

Javascript#1
Krishan-Mishra wants to merge 4 commits into
mainfrom
javascript

Conversation

@Krishan-Mishra

Copy link
Copy Markdown
Owner
  1. Added the generate book data code
  2. Added the promise fetch functionality to render the data in frontend including all search implmentation

Comment thread .gitignore Outdated
@@ -0,0 +1 @@
node_modules/ No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add last line as empty.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread display_books_promise.js Outdated
function IdButton(event) {
event.preventDefault();
const idValue = document.getElementById("input-search-id").value;
if (idValue.trim().length <= 0) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why length will go less than 0.
The above line can be written as -

if (i!dValue.trim().length) return;

Please validate.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread display_books_promise.js Outdated
})
.catch((error) => console.log(error));

document.getElementById("btn-search-id").onclick = IdButton;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read about how onClick event is added in ES6.
The above line can be written as -

document.getElementById('btn-search-id').addEventListener('click', IdButton);

The function naming is not self explanatory. What is the work of IdButton?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly there are other instances where improvement is needed.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread display_books_promise.js Outdated
function genreButton(event) {
event.preventDefault();
const genreValue = document.getElementById("input-search-genre").value;
if (genreValue.trim().length <= 0) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread index.html Outdated
id="div-search-price"
class="container"
style="margin-bottom: 20px; padding-top: 20px"
>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use an extra line for this closing bracket. Add it in the line 20 itself. Implement it at all the instances

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread generate_books.js Outdated

const bookList = new Array();

for (let i = 1; i <= 100; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use some more meaningful name instead of "i" like index or something

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread .gitignore Outdated
@@ -0,0 +1 @@
node_modules/ No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove git error

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread display_books_promise.js Outdated
document.getElementById("btn-search-genre").onclick = genreButton;
document.getElementById("btn-search-price").onclick = priceButton;

function IdButton(event) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ES6 syntax

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread generate_books.js Outdated
}
}

function generateRandomBook(bookId) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this method to inside in class

Comment thread generate_books.js Outdated
@@ -0,0 +1,43 @@
const fs = require("fs");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra space

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Comment thread index.html
</head>

<body>
<div

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use semantic tag

Comment thread index.html
<form action="#">
<input
type="text"
id="input-search-id"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use id instead use class

Comment thread index.html Outdated
type="text"
id="input-search-genre"
class="form-control"
style="width: 25%; display: inline"

@AyushChaudhary2002 AyushChaudhary2002 Sep 18, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add separate style file

Comment thread display_books_promise.js Outdated
@@ -0,0 +1,66 @@
let BookData = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is usually a way to name the class. Variable name should be - let bookData = [];

Comment thread display_books_promise.js Outdated
insertDataInHtml(matchingBooks);
};

const searchByGenreButton = (event) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of event use evt.
event is not a reserved keyword, but it is a global variable in IE at least.

Comment thread generate_books.js Outdated
Comment on lines +14 to +17
const price = faker.finance.amount(5, 30, 2);
this.bookId = bookId;
this.genre = genre;
this.price = price;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining a price variable you can directly used as follows -
this.price = faker.finance.amount(5, 30, 2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants