Help with Javascript I have to make a dowhile loop that will

Help with Javascript!

I have to make a do-while loop that will call this function multiple times to create multiple objects.

Create a Boolean variable, then make a while loop as long as that variable is true.  Inside the while loop, set the Boolean to the answer you get from a confirm() dialog box that asks if they want to continue adding family members. Example: confirm(\"Do you want to continue adding family members?\");

Also inside the while loop, call the buildPerson() function.  Assign the person object that is returned to a variable, then add that variable to an array. Example, if the person object is in a variable called person you could do this: myFamily.push(person);

I\'m really confused on how to make the loops work.

This is what I have so far

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;
}

var addFamily;

var person;

var myFamily[];

do {

while(addFamily == true){

buildPerson();

myFamily.push(person);

confirm(\"Do you want to continue adding family members?\");

}

} while (addFamily == true);

Solution

Hi..I would like clarify few doubts regarding this.

1. If you like to add family members then Boolean will be set to True Else False.Is this you want?

2. So, where are you exactly facing the problem? Do you want us to code your requirement or want to fix the error.

Please let us know.

Help with Javascript! I have to make a do-while loop that will call this function multiple times to create multiple objects. Create a Boolean variable, then mak

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site