New in javascript please help me to do the book tracking app

Please help me to do a Book Tracking App . I take the openclassroom course but unfortunately I m struggling how to do it… below is the code I did but its not yet complete

export class Book {
   constructor(title, author, pages, description, currentPage, read) {
    this.title = title;
    this.author = author;
    this.pages = pages;
    this.description = description;
    this.currentPage = currentPage;
    this.read = read;
  } 
}  

let firstBook = new Book('The Ghost', 'Melinda Gordon', 300, 'Horror', 100, true);
let secondBook = new Book('The Spirit', 'Marie Natividad', 500, 'Fantasy', 100, true);
let thirdBook = new Book('The Heaven', 'Angela Natividad', 900, 'Fantasy', 100, true);
export const books = [firstBook, secondBook, thirdBook];

You will need to provde more than this. What are the requirements? Are there tests? what do they say? can you give the link to the challenge?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

thank you so much for the help and reply this is the website where I take the test

I’m not quite understanding what is it you are trying to achieve. You are basically just exporting a class, which is a way you use to build an object. So your Book class will have a constructor (things of which a book is made of) and methods (actions on a book).

Here there are no methods, instead after building your class, you are building 3 different objects of that class and putting them into an array. Where is your struggle?

Hi Groosterm thank you for the help to inform you what will be the exact test that I will need to do here’s the below instruction from them Your job is to create the Book class, and to populate the development database with three or four books to make sure the interface works properly — you will be working with the provided Book.js file.

The Book class must have the following fields:

  • title - string - title of the book
  • author - string - author of the book
  • description - string - description of the book
  • pages - number - total number of pages
  • currentPage - number - page the user is currently on (between 1 and pages )
  • read - boolean - whether the user has read the book or not (default: false )

The Book class must also have the following instance method:

  • readBook(page)
    • allows the user to say which page they are currently on
    • if the page argument is less than one or more than the total number of pages of the book, readBook must return 0
    • if the page argument is greater than or equal to 1 and less than the total number of pages of the book, readBook must set the instance’s currentPage field to the value passed as an argument and return 1
    • if the page argument is equal to the total number of pages of the book, readBook must set the instance’s currentPage field to the value passed as an argument, set the instance’s read field to true , and return 1

Once you have created the Book class, you will create at least three valid instances of it and place them inside the exported books Array. To check your work, refresh the Codevolve integrated browser: your Book instances should be visible in the carousel of the RestfulReading interface.

To test your readBook instance method, you must follow these instructions for three books (without refreshing the page):

  • update the current page with a valid page that is less than the total number of pages
  • update the current page with the exact total number of pages (the book should disappear from the carousel and appear in the “Read” list)

I think I just in the first part but struggling how to do the other steps or test

Sorry for the delay, got a wedding last weekend :stuck_out_tongue:
Would be unfair if I told you the solution, but I can guide you through it. First of all, the read should be false by default, so you need to do something to your constructor. Can you guess what?

Also, the next step is to create a method inside the class. This is pretty much like writing a function, but its scope will be limited to the specific instance of the class you created; good news is, you only have to define it once inside the class. Let me know if you need further help.

Hi Groosterm its okay no worries I’m glad you reply and willing to help me… well I think I already made some additional codes on my program but I guess I will be needing help on it since for sure there will be errors on it your GUIDE WILL BE SO MUCH APPRECIATED because you know not all people will give time to me to teach me most of people will just say go to others … Well this is my new code

class Book {
constructor(title, author, pages, description, currentPage, read) {
this.title = title;
this.author = author;
this.pages = pages;
this.description = description;
this.currentPage = currentPage;
this.read = read;

if (pages === 0) { 
  this.read = false;
} else if (currentPage < 1 && currentPage > pages) {
  this.read = false;
} else if ( currentPage >= 1 && currentPage < pages) {
  this.currentPage = 
  this.read = true;
} else if (currentPage === pages)
  this.read = true;

}
}

let firstBook = new Book(‘The Ghost’, ‘Melinda Gordon’, 300, ‘Horror’, 400, true);
let secondBook = new Book(‘The Spirit’, ‘Marie Natividad’, 300, ‘Fantasy’, 100, true);
let thirdBook = new Book(‘The Heaven’, ‘Angela Natividad’, 300, ‘Fantasy’, 300, true);
export const books = [firstBook, secondBook, thirdBook];

you told me that the read must be FALSE by default why it should be FALSE?

thanks much
Angel

Well, if you read what you’re supposed to do, you can see:

  • read - boolean - whether the user has read the book or not (default: false)

So that’s one thing.

This won’t work, because you straight up defined the logic of the method, but you didn’t define the method. I would suggest you breeze through freecodecamp’s tutorials on JS, they are very well made, but briefly speaking, a method is a function inside the class, without the keyword function

thank you very much for the information you share I think I will try to take the javascript course you said hope its free :smiley:

Of course! Everything on this site is completely free. All you are asked is a donation, but it’s not mandatory :slight_smile: