0
0
Javascriptprogramming~10 mins

Nested objects 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 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'
A'New York'
BNew York
C'city'
Dcity
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Forgetting to put quotes around string values.
Using the key name instead of the value.
2fill in blank
medium

Complete 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'
A'123-456-7890'
B[ '123-456-7890' ]
C{ mobile: '123-456-7890' }
D1234567890
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a string directly instead of an object.
Using an array instead of an object.
3fill in blank
hard

Fix 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'
ApostalCode
Bpostcode
Cpostal_code
Daddress
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using incorrect key names like 'postcode' or 'postal_code'.
Mixing camelCase and snake_case.
4fill in blank
hard

Fill 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'
Aname
Bage
Cusername
Dyears
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using keys that don't match the console.log statement.
Using incorrect property names like 'username' or 'years'.
5fill in blank
hard

Fill 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'
Aname
Bauthor
Cyear
Dtitle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong keys like 'name' instead of 'title'.
Mixing up the order of keys.