Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Created September 24, 2013 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencombs/6691936 to your computer and use it in GitHub Desktop.
Save stevencombs/6691936 to your computer and use it in GitHub Desktop.
// Javascript Getting Started with Programming
// A Codecademy Javascript (Try it Out!) assignment
// Dr. Steven B. Combs, coding novice
// 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 (alice, billy));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment