29. Try It Out Syntax error


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

// Make a new function, olderAge, to return the age of
// the older of two people
function olderAge (person 1, person2) {
if(person1.age > person2.age) {
return person1.age;
}
else if (person1.age < person2.age) {
return person2.age;
}
else {
return person1.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));

I think this is coming along the right lines but I can't seem to find the syntax error. Care to point me in the right direction?


#2

In your olderAge function you have a space between person and 1. Removing this should fix it :smile:


#3

:cat2: I HEART CATS!!!! YAY!!!
also, this 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
function oldergAge(person1, person2) {
if(person1.age > person2.age) {
retrun 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));

what's wrong!?!?!


#4

In your function you wrote "oldergAge" it's olderAge


#5

lol ... why is improving the syntax such a pain?


#6

Ive got this (txt below) how is that wrong?

// 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

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

// the older of two people

// 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));


#7

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

}

#8

I also have a syntaxis error, what's wrong?
// 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 oderAge = 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(alice, billy));


#9

not var oder Age but
var olderAge

you just lost L in word older


#10

Hope this helps. Usually I need to see what it looks like when its right..


#11

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

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

both are working , really i understand something :slight_smile: