Chào mọi người, mình gặp một bài trên HackerRank về Abstract Class ở đây. Đoạn code mình viết khi chạy thì in ra màn hình đúng format nhưng HackerRank báo là wrong answer như hình. Mình muốn hỏi mình cần sửa chỗ nào?
Đây là câu hỏi
Given a Book class and a Solution class, write a MyBook class that does the following:
- Inherits from Book
- Has a parameterized constructor taking these parameters:
- string
- string
- int
- Implements the Book class’ abstract display() method so it prints these lines:
- , a space, and then the current instance’s .
- , a space, and then the current instance’s .
- , a space, and then the current instance’s .
Ví dụ input là
The Alchemist
Paulo Coelho
248
In ra theo format như sau:
Title: The Alchemist
Author: Paulo Coelho
Price: 248
Còn đây là đoạn code mình viết bằng javascript.
// Declare your class here.
class MyBook extends Book {
/**
* Class Constructor
*
* @param title The book's title.
* @param author The book's author.
* @param price The book's price.
**/
// Write your constructor here
constructor(title, author, price) {
super(title, author);
this.price = price;
}
/**
* Method Name: display
*
* Print the title, author, and price in the specified format.
**/
// Write your method here
display() {
console.log('Title: ' + this.title);
console.log('Author: ' + this.author);
console.log('Price' + this.price);
}
// End class
}