CIT 261 - Fluency Evidence: JavaScript Objects

Constructors:

                
var myFirstObject = new Object();
var mySecondObject = {};
var myThirdObject = {
    volume: "Book of Mormon",
    book: "Moroni",
    chapter: "10",
    verses: "3-5"
}
                
            

myFirstObject:

mySecondObject:

myThirdObject:

Properties:

                
myFirstObject.name = "Sterling";
mySecondObject["temperature"] = 47.3;
myThirdObject.volume = "New Testament"
myThirdObject.book = "John"
myThirdObject["chapter"] = "1"
myThirdObject["verses"] = "1"                
            

myFirstObject:

mySecondObject:

myThirdObject:

Methods:

                
var generalConference = {
    month: "April",
    location: "Salt Lake City",
    daysUntil: function () {
        var today = new Date();
        var conf = new Date(today.getFullYear(), 3, 6);
        const one_day = 1000*60*60*24;
        return Math.ceil((conf.getTime()-today.getTime())/one_day);
    }
}
               
            

General Conference Month:

General Conference Location:

Days Until General Conference:

Multiple Instances:

                
// Preparing for multiple instances of an object
var classMates = [];
function ClassMate(lastName, firstName, expertise) {
    this.lastName = lastName,
    this.firstName = firstName,
    this.expertise = expertise,
    this.helloString = function () {
        return "Hail, " + this.firstName + " " + this.lastName + 
        ", master of " + this.expertise;
    }
}

// Create an array of objects
classMates.push(new ClassMate("Wright", "Sterling", "napping"));
classMates.push(new ClassMate("Doe", "John", "Java"));
classMates.push(new ClassMate("Torvalds", "Linus", "Linux"));
               
            

First Instance:

Second Instance:

Third Instance: