Hi @chrisdavidmills! How are you!? I’m here with this code in where I can’t find why it doesn’t work. Could be because I didn’t define separately the pronoun? Tks man!
<script>
function Person(first, last, age, gender, interests) {
this.name = {
'first': first,
'last' : last
};
this.age = age;
this.gender = gender;
this.interests = interests;
this.bio = function() {
var firstString = this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. ';
if(this.gender === 'male') {
firstString += 'He likes';
} else if(this.gender === 'female') {
firstString += 'She likes';
} else {
firstString += 'They like';
}
for(i = 0; i < this.interests.length; i++) {
if(this.interests.length === 1) {
firstString += this.interests[0] + '.';
} else if(this.interests.length === 2) {
firstString += this.interests[0] + ' and ' + this.interests[1] + '.';
} else {
for(i = 0; i < this.interests.length; i++) {
if(i === this.interests.length -1) {
firstString += 'and ' + this.interests[i] + '.';
} else {
firstString += this.interests[i] + ', ';
}
}
}
}
alert(firstString);
}
}
var person1 = new Person('Bob', 'Smith', 32, 'male', ['music', 'skiing']);
var person2 = new Person('Robert', 'Diven', 12, 'male', ['games', 'more games']);
var person3 = new Person('Sarah', 'White', 52, 'female', ['cosmethics']);
var person4 = new Person('Meli', 'Dib', 32, 'female', ['music', 'skiing','cooking','going out with friends']);
var person5 = new Person('Rob', 'Mark', 32, 'other', ['music', 'skiing']);
</script>