Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: JavaScript  |  size: 0.71 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Our person constructor
  2. function Person (name, age) {
  3.     this.name = name;
  4.     this.age = age;
  5. }
  6.  
  7. // We can make a function which takes persons as arguments
  8. // This one computes the difference in ages between two people
  9. var ageDifference = function(person1, person2) {
  10.     return person1.age - person2.age;
  11. };
  12.  
  13. // Make a new function, olderAge, to return the age of
  14. // the older of two people
  15. var olderAge = function (person1, person2) {
  16.     return person1.age > person2.age : person1.age ? person2.age;
  17. };
  18.  
  19. // Let's bring back alice and billy to test our new function
  20. var alice = new Person("Alice", 30);
  21. var billy = new Person("Billy", 25);
  22.  
  23. console.log("The older person is "+olderAge(alice, billy));