person details:
Give an object person containing a person details, write Js to log the name, address ,nicknames count.
input: The input will be a single line containing an object person
output: The first line of out put should contain the name and address of the person as shown in the sample output
The second line of output should contain the nicknames count of the person as shown in the sample output.
Constraints: The keys of object should be in quotes while giving the input.
input:{'name': 'Pranay', 'address': {'city': 'Mumbai', 'state': 'Maharashtra'}, ' nickNames': ['Nani', 'Chanti ']}
out put become:
Pranay is Mumbai, Maharashtra
Pranay has 2 nicknames.
function personDetails (obj) {
const name = obj.name;
const countNicknames = obj.nickNames.length;
const address = Object.values(obj.address).join(', ');
return `${name} is ${address}\n${name} has ${countNicknames} nicknames`
}
let input = {'name': 'Pranay', 'address': {'city': 'Mumbai', 'state': 'Maharashtra'}, 'nickNames': ['Nani', 'Chanti ']}
console.log(personDetails(input));
Comments
Leave a comment