Javascript - Hiển thị thông tin từ một đối tượng

Viết chương trình JavaScript để hiển thị  tên sách, tên tác giả và trạng thái đang đọc của những cuốn sách sau:

Mã nguồn:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Reading status of a book library</title>
	<script>
		var library = [ 
    {
        title: 'Bill Gates',
        author: 'The Road Ahead',
        readingStatus: true
    },
    {
        title: 'Steve Jobs',
        author: 'Walter Isaacson',
        readingStatus: true
    },
    {
        title: 'Mockingjay: The Final Book of The Hunger Games',
        author: 'Suzanne Collins',
        readingStatus: false
    }];

	for (var i = 0; i < library.length; i++) 
	   {
		var book = "'" + library[i].title + "'" + ' by ' + library[i].author + ".";
		if (library[i].readingStatus) {
		  document.write("Already read " + book);
		} else
		{
		 document.write("You still need to read " + book);
		}
	   }
	</script>
</head>
<body>
</body>
</html>

Xem ví dụ

Lưu đồ thuật toán:

Flowchart: JavaScript - Gather and display infromation from an object.


Chatbot Tư vấn Lộ trình CNTT 🤖
Chào bạn! Tôi có thể tư vấn về các lộ trình học CNTT dựa trên roadmap.w3typing.com. Hãy chọn một từ khóa dưới đây hoặc gõ câu hỏi của bạn (ví dụ: "Frontend", "Backend", "Python", "DevOps").