javascript/problems/object-properties/problem.md at master · hackademymx/javascript · GitHub
Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 883 Bytes

File metadata and controls

43 lines (28 loc) · 883 Bytes

You can access and manipulate object properties –– the keys and values that an object contains –– using a method very similar to arrays.

Here's an example using square brackets:

const example = {
  pizza: 'yummy'
}

console.log(example['pizza'])

The above code will print the string 'yummy' to the terminal.

Alternately, you can use dot notation to get identical results:

example.pizza

example['pizza']

The two lines of code above will both return yummy.

The challenge:

Create a file named object-properties.js.

In that file, define a variable named food like this:

const food = {
  types: 'only pizza'
}

Use console.log() to print the types property of the food object to the terminal.

Check to see if your program is correct by running this command:

javascripting verify object-properties.js