Skip to main content
Table of contents

Back to challenges

Challenge 4 - 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() the following sentence:

"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."

Ignore the brackets. They’re just there to let you know a word should be replaced with something else. The sentence you log should look like this:

"Hi, my name is Virginia Woolf. I am 59 years old, and work as a writer."

Here is the array:

var 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
  },
];

BONUS

If you want an extra challenge, only console.log() the writers that are alive.

Solution

Next challenge

This page was last reviewed on 3 February 2022. It needs to be reviewed again on 3 February 2023 .
This page was set to be reviewed before 3 February 2023. This might mean the content is out of date.