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>
Lưu đồ thuật toán: