Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the city name inside the nested object.
Javascript
const person = { name: 'Alice', address: { city: [1], zip: '12345' } };
console.log(person.address.city); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Forgetting to put quotes around string values.
Using the key name instead of the value.
β Incorrect
The city name is a string value, so it must be enclosed in quotes.
2fill in blank
mediumComplete the code to add a nested object for the phone number inside the contact object.
Javascript
const contact = { email: 'alice@example.com', phone: [1] };
console.log(contact.phone.mobile); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a string directly instead of an object.
Using an array instead of an object.
β Incorrect
The phone property should be an object with a mobile property as a string.
3fill in blank
hardFix the error in accessing the nested property to get the postal code.
Javascript
const data = { location: { address: { postalCode: '90210' } } };
console.log(data.location.[1].postalCode); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using incorrect key names like 'postcode' or 'postal_code'.
Mixing camelCase and snake_case.
β Incorrect
The correct key to access the postal code is 'address', not 'postcode' or others.
4fill in blank
hardFill both blanks to create a nested object with a name and an age property inside the user object.
Javascript
const user = { profile: { [1]: 'Bob', [2]: 30 } };
console.log(user.profile.name, user.profile.age); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using keys that don't match the console.log statement.
Using incorrect property names like 'username' or 'years'.
β Incorrect
The nested object keys should be 'name' and 'age' to match the console.log access.
5fill in blank
hardFill all three blanks to create a nested object representing a book with title, author, and year properties.
Javascript
const book = { info: { [1]: '1984', [2]: 'George Orwell', [3]: 1949 } };
console.log(book.info.title, book.info.author, book.info.year); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using wrong keys like 'name' instead of 'title'.
Mixing up the order of keys.
β Incorrect
The keys must be 'title', 'author', and 'year' to match the console.log output.