forked from HackYourFuture/JavaScript1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_readingLIST.js
More file actions
56 lines (44 loc) · 1.28 KB
/
4_readingLIST.js
File metadata and controls
56 lines (44 loc) · 1.28 KB
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
'use strict'
const books = [
{
title: 'Steppenwolf',
alreadyRead: true,
author: 'Hermann Hesse'
},
{
title: 'Norwegian Wood',
alreadyRead: true,
author: 'Haruki Murakami'
},
{
title: 'The Republic',
alreadyRead: false,
author: 'Plato'
}
];
for(let i = 0; i < books.length; i = i + 1) {
const book = books[i];
// you print the title
console.log(book.title + " by " + book.author);
// if you read it then say i read it
if (book.alreadyRead) { console.log("You already read " + book.title);
// if you didn't read it then say still need to read
} else {
console.log("You still need to read " + book.title); }
// adds space in between the books. Let's give it a face lift!
console.log("");
}
/*I still feel like this code is well above my capabilities. I will need to invest some more time into breakjng it down peice by piece.
let booksRead = [];
for(let i = 0; i <= 2; i++) {
const book = books[i];
let sentence = book.title + " by " + book.author;
console.log(sentence);
if (book.alreadyRead) {
booksRead.push("You already read " + book.title);
} else {
booksRead.push("You still need to read " + book.title);
}
}
booksRead.forEach(sentence => console.log(sentence));
*/