This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var num = 10; | |
while(num > 0) { | |
if(num % 2 === 0) { | |
console.log(num); | |
} | |
num--; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function oldestLivingParent(people) { | |
var livingParents = {}; | |
var sortedByAge = []; | |
var oldestLivingParent = false; | |
var isDead = function(p) { | |
return !person.age; | |
}; | |
var isParent = function(p) { | |
return !!livingParent[p.name]; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function StudentReport() { | |
this.grade1 = 4; | |
this.grade2 = 2; | |
this.grade3 = 1; | |
// to hide the grades and to display gpa only | |
// change this to var in grade properties. | |
this.getGPA = function() { | |
return (this.grade1 + this.grade2 + this.grade3) / 3; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Dog (breed) { | |
this.breed = breed; | |
}; | |
// sayHello method for the Dog class | |
// all dogs can now say hello | |
Dog.prototype.sayHello = function() { | |
console.log("Hello I'm a " + this.breed + " dog."); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var languages = { | |
english: "Hello!", | |
french: "Bonjour!", | |
notALanguage: 4, | |
spanish: "Hola!" | |
}; | |
// prints hello in 3 different languages. | |
// for in loops through all the properties one by one | |
// assigning the property name to x on each run of the loop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(first,last,age) { | |
this.firstname = first; | |
this.lastname = last; | |
this.age = age; | |
var bankBalance = 7500; | |
this.askTeller = function(pass) { | |
if (pass == 1234) return bankBalance; | |
else return "Wrong password."; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(first,last,age) { | |
this.firstname = first; | |
this.lastname = last; | |
this.age = age; | |
var bankBalance = 7500; | |
var returnBalance = function() { | |
return bankBalance; | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(first,last,age) { | |
this.firstname = first; | |
this.lastname = last; | |
this.age = age; | |
var bankBalance = 7500; | |
this.getBalance = function() { | |
// return the bankBalance | |
return bankBalance; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// original classes | |
function Animal(name, numLegs) { | |
this.name = name; | |
this.numLegs = numLegs; | |
this.isAlive = true; | |
} | |
function Penguin(name) { | |
this.name = name; | |
this.numLegs = 2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Penguin(name) { | |
this.name = name; | |
this.numLegs = 2; | |
} | |
// the Emperor class | |
function Emperor(name) { | |
this.name = name; | |
} |