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.
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
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
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