Try it out!


#1

https://www.codecademy.com/en/courses/spencer-sandbox/4/4?curriculum_id=506324b3a7dffd00020bf661#

whenever I run my code, I always get an error message that says, " Oops, try again. Your code caused the following error: TypeError: olderAge is not a function. (In ‘olderAge(michael,nicole)’, ‘olderAge’ is undefined)"


// 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", 30);
var bob = new Person("Bob", 25);

console.log("The older person is " + olderAge(alice, bob));
var olderAge = function(person1, person2) {
   if(person1.age > person2.age) {
     return person1.age;  
   }
   else {
       
   }
};


#2

here:

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

you call the olderAge function before defining it, that will throw an error


#3

Thank you! I cannot believe that I missed something that obvious!


#4