15 heures
- Facile
Ce cours est visible gratuitement en ligne.
course.header.alt.is_video
course.header.alt.is_certifying
J'ai tout compris !Mis à jour le 04/05/2022
Help create a book-tracking app for readers!
Compétences évaluées
- Write clean and maintainable code using methods in JavaScript
Description
How to complete this quiz
This activity is a great opportunity to practice some of the more important elements you have learned throughout the course, and to see how they could be used in a real-world application. To pass this test, go to this online exercice on Next.tech and follow the instructions. Write your code on the file Book.js
to perform the required tasks. Reload the mini browser to see your changes take place.
Your mission, should you choose to accept it
After your work on the video streaming website, you are asked to build an app called RestfulReading, which will allow users to keep track of the books they are reading/have read.
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 bookauthor
-string
- author of the bookdescription
-string
- description of the bookpages
-number
- total number of pagescurrentPage
-number
- page the user is currently on (between 1 andpages
)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 return0
- 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'scurrentPage
field to the value passed as an argument and return1
- if the
page
argument is equal to the total number of pages of the book,readBook
must set the instance'scurrentPage
field to the value passed as an argument, set the instance'sread
field totrue
, and return1
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)
Question 1
Which of the following words appears in the browser alert when you complete the activity?
cats
dogs
puppies
kittens
goats
lambs