Beginners JavaScript
  • Welcome!
  • Tutorial
    • Step 1: Hello World
    • Step 2: Data Types
    • Step 3: Comments
    • Step 4: Variables
    • Step 5: If/Else Statements
    • Step 6: For Loops
    • Step 7: Functions
    • Step 8: Arrays
    • Step 9: Objects
  • Challenges
    • Challenge 1: Age Difference
    • Challenge 2: Famous Writers
    • Challenge 3: Fix the Code
    • Challenge 4: FizzBuzz
    • Challenge 5: Needle in a Haystack
Powered by GitBook
On this page
  1. Challenges

Challenge 2: 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
  },
];
PreviousChallenge 1: Age DifferenceNextChallenge 3: Fix the Code

Last updated 6 years ago

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