0
0
Javascriptprogramming~10 mins

Accessing object properties in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the value of the 'name' property from the object.

Javascript
const person = { name: 'Alice', age: 25 };
console.log(person.[1]);
Drag options to blanks, or click blank then click option'
Aage
Bperson
Cname
Dvalue
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the wrong property name.
Trying to access the object itself instead of its property.
2fill in blank
medium

Complete the code to access the 'age' property using bracket notation.

Javascript
const person = { name: 'Bob', age: 30 };
console.log(person[[1]]);
Drag options to blanks, or click blank then click option'
Aname
B'name'
Cage
D'age'
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Not using quotes around the property name.
Using the wrong property name.
3fill in blank
hard

Fix the error in accessing the 'city' property from the object.

Javascript
const location = { city: 'Paris', country: 'France' };
console.log(location[1]);
Drag options to blanks, or click blank then click option'
A['city']
B.city()
C.city
Dcity
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using parentheses like a function call.
Omitting quotes in bracket notation.
4fill in blank
hard

Fill both blanks to create an object with a property and access it using bracket notation.

Javascript
const obj = { [1]: 100 };
console.log(obj[[2]]);
Drag options to blanks, or click blank then click option'
A'score'
C'points'
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different property names in object and access.
Omitting quotes around property names.
5fill in blank
hard

Fill all three blanks to create an object and access a nested property.

Javascript
const data = { user: { [1]: 'John' } };
const key = [2];
console.log(data.user[[3]]);
Drag options to blanks, or click blank then click option'
A'firstName'
Ckey
D'lastName'
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using dot notation with a variable instead of bracket notation.
Mismatching property names.