Using Javascript, Create a function called build person. It will not have any in
ID: 3788262 • Letter: U
Question
Using Javascript,
Create a function called build person. It will not have any input parameters, but it will return an object that represents a person.
Inside this function, use individual prompt statements to ask the user for the family member’s: full name, age, relationship (to you), favorite color, and favorite food. For example: Joe Smith, 79, grandpa, brown, prunes. Collect these bits of data in local variables inside the function. Example: var fullName = prompt("What is their full name?");
Once you have variables that contain each of these items, create a new object that contains these values and add them to the object. Then, return the object from the function.
Explanation / Answer
Here is code:
function buildPerson() {
// prompt for input
var fullName = prompt("Enter full name");
var age = prompt("Enter your age");
var relationship = prompt("Enter relationship ");
var color = prompt("Enter your favorite color");
var food = prompt("Enter your favorite food");
//assign value
var familyMember = new Object();
familyMember.name = fullName;
familyMember.age = age;
familyMember.relationship = relationship;
familyMember.color = color;
familyMember.food = food;
return familyMember;
}
How to call?
// result hold the return value of buildPerson famillyMember object
var result = buildPerson();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.