Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using the wrong property name.
Trying to access the object itself instead of its property.
β Incorrect
To access the 'name' property of the object, use dot notation with 'name'.
2fill in blank
mediumComplete 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Not using quotes around the property name.
Using the wrong property name.
β Incorrect
Bracket notation requires the property name as a string inside quotes.
3fill in blank
hardFix 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using parentheses like a function call.
Omitting quotes in bracket notation.
β Incorrect
To access a property with bracket notation, use brackets and quotes: ['city'].
4fill in blank
hardFill 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using different property names in object and access.
Omitting quotes around property names.
β Incorrect
The property name must be the same string in the object and when accessed with brackets.
5fill in blank
hardFill 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using dot notation with a variable instead of bracket notation.
Mismatching property names.
β Incorrect
The nested property is 'firstName', stored in variable 'key', used to access the property.