This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy path1-writers.js
More file actions
66 lines (57 loc) · 1.74 KB
/
1-writers.js
File metadata and controls
66 lines (57 loc) · 1.74 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
57
58
59
60
61
62
63
64
65
66
/* Challenge 1: Famous Writers
Did you know you can also have an array of objects? We've created one for you here. Loop through the array,
and for each object, `console.log()` out the sentence:
"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
Here is the array:
*/
let writers = [
{
firstName: "Virginia",
lastName: "Woolf",
occupation: "writer",
age: 59,
alive: false
},
{
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 41,
alive: true
},
{
firstName: "Jane",
lastName: "Austen",
occupation: "writer",
age: 41,
alive: false
},
{
firstName: "bell",
lastName: "hooks",
occupation: "writer",
age: 64,
alive: true
}
];
/* for (let key in writers){
//console.log(writers[key]);
console.log(` Hi, my name is ${writers[key].firstName} ${writers[key].lastName}. I am ${writers[key].age} years old, and works as a ${writers[key].occupation}.`);
} */
///////////////////////////////////////////////////////////
//Writing with forEach() array method;
let writeNames = writers.forEach(writer => {
console.log (` Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old, and works as a ${writer.occupation}.`)
})
/////////////////////////////////////////////////////////////
/*
If you want an extra challenge, only `console.log()` the writers that are alive.
*/
for (let key in writers){
if(writers[key].alive === true){
console.log(` Hi, my name is ${writers[key].firstName} ${writers[key].lastName}. I am ${writers[key].age} years old, and works as a ${writers[key].occupation}.`);
}
else{
console.log(`${writers[key].firstName} ${writers[key].lastName} is death.`)
}
}