I'm learning Javascript and trying to complete the following exercise:
"Write a script that creates objects for people named Ani, Sipho, Tuulia, Aolani, Hiro, and Xue, such that:
Tuulia is the mother of Sipho. Ani and Sipho are married. The children of Ani and Sipho are, in order, Aolani, Hiro, and Xue. Define each of the person objects with as many of the following properties as you can fill in: name, mother, father, spouse, and children. The childrenproperty should have an array value. Also create a method for the person object that allows the spouse property to be changed.
console.log(sipho.mother);
// tuulia
ani.changeSpouse("mars");
console.log(ani.spouse);
// mars"
The code I have so far is:
var ani = {name: 'Ani', children:[]};
var tuulia = {name: 'Tuulia'};
var sipho = {name: 'Sipho', mother: 'Tuulia', spouse: 'Ani', children:[]};
var aolani = {name: 'Aolani', mother: 'Ani', father: 'Sipho'};
var hiro = {name: 'Hiro', mother: 'Ani', father: 'Sipho'};
var xue = {name: 'Xue', mother: 'Ani', father: 'Sipho'};
this.changeSpouse = function (spouse) {
this.spouse = name;
}
console.log(sipho.mother);
ani.changeSpouse("mars");
console.log(ani.spouse);
so, right now I'm able to get the mother name for console.log(sipho.mother).
I'm having trouble with creating a function to change the spouse name. Could anyone please point where I'm going wrong with this?
Also, I'm not entirely sure if I'm doing "the childrenproperty should have an array value." correctly.