This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Displaying People) assignment | |
// Dr. Steven B. Combs, coding novice | |
// Create an address book from objects | |
// bob object | |
var bob = { | |
firstName: "Bob", | |
lastName: "Jones", |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Methods) assignment | |
// Dr. Steven B. Combs, coding novice | |
// Radius Function | |
function Circle (radius) { | |
this.radius = radius; | |
this.area = function () { | |
return Math.PI * this.radius * this.radius; | |
}; |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Customizing Constructors) assignment | |
// Dr. Steven B. Combs, coding novice | |
// This format requires three lines to create a Book object | |
var harry_potter = new Object(); | |
harry_potter.pages = 350; | |
harry_potter.author = "J.K. Rowling"; | |
// This format requires a single line to create a Book object |
This file contains 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
// 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; | |
} |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Loop the loop) assignment | |
// Dr. Steven B. Combs, coding novice | |
// Person constructor | |
function Person(name,age) { | |
this.name=name; | |
this.age=age; | |
} |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Constructors in Review - Rabbits) assignment | |
// Dr. Steven B. Combs, coding novice | |
// Define Rabbit adjective constructor | |
function Rabbit(adjective) { | |
this.adjective = adjective; | |
this.describeMyself = function() { | |
console.log("I am a " + this.adjective + " rabbit"); | |
}; |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (More Kinds of Methods) assignment | |
// Dr. Steven B. Combs, coding novice | |
var square = new Object(); // Create 'square' object | |
square.sideLength = 6; // Set square side length 6 | |
square.calcPerimeter = function() { // Calculate perimeter function | |
return this.sideLength * 4; // Return value of the perimeter method | |
}; | |
square.calcArea = function() { // Calculate area function |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Make Your Own Method) assignment | |
// Dr. Steven B. Combs, coding novice | |
var rectangle = new Object(); // New object 'rectangle' | |
rectangle.height = 3; // Rectangle height 3 | |
rectangle.width = 4; // Rectangle width 4 | |
rectangle.setHeight = function (newHeight) { // Set rectangle height function | |
this.height = newHeight; // Use 'this' as placeholder to modify object called |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Make Your Own Method) assignment | |
// Dr. Steven B. Combs, coding novice | |
var setAge = function (newAge) { // New function | |
this.age = newAge; // Use this as a method placeholder for the function | |
}; | |
var bob = new Object(); // New object 'bob' | |
bob.age = 30; // Set 'bob' age |
This file contains 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
// Javascript Getting Started with Programming | |
// A Codecademy Javascript (Function Review) assignment | |
// Dr. Steven B. Combs, coding novice | |
var multiply = function (x, y) { // Create function with two inputs | |
return x * y; // Multiply x and y and return the value | |
}; | |
multiply (10, 10); // Call the function and pass off two values |