29/33 Try it out!


#1

Hi,I already run this exercise well, but I want to print out the older person name as well I try to do it 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

var olderAge = function(person1, person2){
if(person1.age > person2.age){
return person1.age;
}else{
return person2.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.name( ) + " with " olderAge(alice, billy) + " years." );

What is wrong with my code?


#2

if you have already passed this part. you can try something like this

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

var olderAge = function(person1, person2){
                if(person1.age > person2.age){
                    return "The older of the two is "+person1.name+" with "+person1.age+" years";
                }
                else{
                    return "The older of the two is "+person2.name+" with "+person2.age +" years";
                }
            };
// 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(olderAge(alice, billy));

#3

Thank you!! Rydan. That's more simple that I was trying to do.


#4

someone help me to pass this one ..

here is my code..

// 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(Person1, person2);
{
if (person1.age > person2)
{
return person1.age
}
else
{
return person2.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));

but console shows an error- SyntaxError: Expected '{' Its really frustrating, some help me please


#5

try this errors corrected

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(person1, person2){// No semicolon after the ')'
                if (person1.age > person2){return person1.age;}
                else{return person2.age;}
            };
var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);

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

#6

thanks rydan.. that was really a silly mistake by me.. :smile:


#7

Want to say thanks for this. My error was that I didn't include parameter in () after var ageDifference = function()

In fact I didn't need the = sign between ageDifference and function. Is the = sign optional here?

All the best,

Mark


#8

Sorry for the offtopic, but please help if you can :wink:

The last few days I have been living in your webpage, IMO its really fun to learn all this stuff. I have learned the basics of HTML and CSS.

My long-term goal wold be to create a website similar to GoFundMe.com (a crowdfunding platform) or at least a simple version of the site.

I hope you could answer this question for me - What skills (coding languages) would I need to learn to do the most work myself?
I realize its basically impossible to do it on my own, but just so I wouldnt have to spend so much on freelancers.

Looking forward to your answert & thanks in advance.