29/33: What am I doing wrong


#1

// Our person constructor
function Person (name, age) {
this.name = name;
this.age = age;
}

// We can make a function which takes persons as arguments
// This one computes the difference in ages between two people
var ageDifference = function(person1, person2) {
return person1.age - person2.age;
}

var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);

// get the difference in age between alice and billy using our function
var diff = new ageDifference(alice.age, billy.age);


#2

the ageDifference() function is not an object so you must not use the new keyword to invoke(call) it
also just using (alice, billy) as argument is correct because the function expects two person objects to be passed but then alice.age and billy.age are Integers


#3

var diff = ageDifference(alice, billy);
worked for me


#4

you can also code in this way.

// Our person constructor
function Person (name, age) {
this.name = name;
this.age = age;
}

// We can make a function which takes persons as arguments
// This one computes the difference in ages between two people
var ageDifference = function(person1, person2) {
return person1.age - person2.age;
};

// Make a new function, olderAge, to return the age of
// the older of two people

// Let's bring back alice and billy to test our new function
var alice = new Person("Alice", 20);
var billy = new Person("Billy", 25);

var olderAge = function(){
olderAge = ageDifference(alice, billy);
if (olderAge > 0){
console.log("The older person is " + alice.age);
} else {
console.log("The older person is " + billy.age);
}
};

but create error but answer is rite


#5

// Our person constructor
function Person (name, age) {
this.name = name;
this.age = age;
}

// We can make a function which takes persons as arguments
// This one computes the difference in ages between two people
var ageDifference = function(person1, person2) {
return person1.age - person2.age;
};

// Make a new function, olderAge, to return the age of
// the older of two people
var olderAge = function(oldAge1, oldAge2) {
if(oldAge1.age > oldAge2.age) {
return oldAge1.age;
}
else if (oldAge1.age < oldAge2.age) {
return oldAge2.age;
}
else {
return oldAge1.age;
}
};

// Let's bring back alice and billy to test our new function
var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);

console.log("The older person is " + olderAge(alice, billy));


#6

var olderAge= function(person1,person2){
if (person1.age>person2.age){
return person1.age;
}
else if (person1.age return person2.age ;
}
else{
if(person1.age>person2.age){
return person1.age
}
else {
return person2.age
}
}
};