-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects-json-js.html
69 lines (66 loc) · 1.75 KB
/
objects-json-js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
'use strict';
// todo:
// Create an array of objects that represent books.
// Each book should have a title and an author.
// The book author should be an object with a firstName and lastName.
// Be creative and add at least 5 books to the array
var books = [
{
'title': '1984',
'author': {
'firstName' : 'George',
'lastName' : 'Orwell'
}
},
{
'title' : 'Brave New World',
'author': {
'firstName' : 'Aldous',
'lastName' : 'Huxley'
}
},
{
'title' : 'Mogworld',
'author' : {
'firstName' : 'Yahtzee',
'lastName' : 'Croshaw'
}
},
{
'title' : 'Air Force Gator',
'author' : {
'firstName' : 'Dan',
'lastName' : 'Ryckert'
}
},
{
'title': 'The Last Wish',
'author' : {
'firstName' : 'Andrzej',
'lastName' : 'Sapkowski'
}
}
];
// log out the books array
console.log(books);
// todo:
// Loop through the array of books using .forEach and print out the specified information about each one.
// start loop here
books.forEach(function(book) {
console.log("Book #" + (books.indexOf(book) + 1));
console.log("Title: " + book.title);
console.log("Author: " + book.author.firstName + " " + book.author.lastName);
console.log("---");
});
// end loop here
</script>
</body>
</html>