Easy
Working with Nested Objects in JavaScript
Description
Objects in JavaScript can contain other objects as properties, creating a nested structure.
This is useful for representing complex data, such as a person with an address or a company with departments.
In this challenge, you will create a function that takes a nested object representing a person and extracts specific information from it.
Example Object Structure:
const person = {name: "Alice",age: 25,address: {city: "New York",zipCode: "10001"}};
Your task is to complete the function getPersonDetails, which should take a person object as a parameter and return a string in the format: "<name> is <age> years old and lives in <city>."
Example Usage:
const person = {name: "John",age: 30,address: {city: "Los Angeles",zipCode: "90001"}};console.log(getPersonDetails(person)); // Expected output: "John is 30 years old and lives in Los Angeles."
Constraints:
- The input will always be a valid object with name, age, and address properties.
- The address property will always be an object with a city property.
- The function should return a string in the specified format.
Did you know?
www stands for World Wide Web.
Test Cases
Input:
{ "age": 40, "name": "Bob", "address": { "city": "San Francisco", "zipCode": "94105" } }
Expected Output:
"Bob is 40 years old and lives in San Francisco."