Answer to Question #312719 in HTML/JavaScript Web Application for sandhya

Question #312719

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.


1
Expert's answer
2022-03-16T14:48:39-0400
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));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS