7. I dont know where to start


#1

Any help would be appreciated..


#2

@jorfizzle23,

# - - - B a s i c s - - -
Each Object has one or more properties.
Each property consists of a property-key and it's associated value.

 var object1 = {
              name: "First"
              }

So object1 has 1 property
a name property with property-key name and it's associated string VALUE "FIRST"

OR

var myObj = {
         type: 'fancy',
         disposition: 'sunny'
        }

myObj has 2 properties seperated by a comma-,,
a type property with property-key type and an associated string VALUE 'fancy'
a disposition-property with property-key disposition and
..an associated string VALUE 'sunny'.

= = = = = = = = = = = = = = = = = = = = = = =

To create an Object,

you can use the literal notation,

you directly create an Instance of the object, with the
properties being separated by a comma-,

  var myObj = {
        type: 'fancy',
        disposition: 'sunny' 
  };

OR

You create an Object by the construct notation.

First you create an empty Object by way of either
myObj = new Object(); or myObj = {};
and then you attach its properties using the syntax
object-name.property-key = it's-associated-value ;
( this.name = x ; )

thus:

  var myObj = {};
      myObj.type = 'fancy';
      myObj.disposition = 'sunny';

OR

There is also the facility Class construct notation.

The name should then start with a Capital-letter.

  var Person = function( theName, theAge ) {
         this.name = theName;
         this.age = theAge;
         this.displayInstance = function() {
           console.log("The displayInstance -output-"+
                       "\n============================" +
                     "\n\t name: " + this.name +
                     "\n\t age: " + this.age);
                       };
       };
    //now create an Instance of this Class-object
  var myObj = new Person("Classy_Rocker",20);
    //call the Method displayInstance which takes NO parameters
  myObj.displayInstance();
  console.log( myObj );
  //you can run this in labs.codecademy.com try it !!

As you can see i created a function within this constructor,
they now call this function a Method.
So if in near future the course is asking you to create a method you now know
that you have to create
a property-key with an associated value being a function within an Object.


#3

@jorfizzle23,

var james = {
    job: "programmer",
   married: false,
   sayJob: function() {
          // complete this method
          console.log("Hi, I work as a" + this.job);
    }
 };

Description of the james object.
The james object has 3 properties and are seperated by a comma-,

there is a job property with property-key job and it's associated string value 'programmer'
there is a married property with property-key married and it's associated boolean value false
there is a sayJob property with property-key sayJob and it's associated anonymous function VALUE
( they also would 'say', the james-object has the sayJob()-Method )

access via dot-notation
james.job ==> you will get the associated string VALUE of the job property-key, thus
you get the string VALUE 'programmer'

james.married ==> you will get the associated boolean VALUE false

james.sayJob ==> you will get the associated anonymous function VALUE
to call/execute this method you add a pair of parenthesis-( )
james.sayJob();

access via the square-bracket-notation
1 using the literal property-key
james["job"]
james["married"]
james["sayJob"]()

2 using the property-key by reference (=== via a variable )
var propertyKey1 = "job";
var propertyKey2 = "married";
var propertyKey3 = "sayJob";
james[propertyKey1] ==> you will get the associated string VALUE of the job property-key, thus
you get the string "programmer"

james[propertyKey2]
in this case you will get the boolean VALUE of the married property
being false

james[propertyKey3]();
would =display= "Hi, I work as a programmer"


9. I dont know where to start
6. I dont know where to start
#4

yeah none of this really helps me. kinda just wanted the answer and not a couple of essays on life. lol


#5

Believe me, he's only trying to help. He sent me these too. But they helped me! You wanted the answer, but I want you to understand how it works. Otherwise, you probably wouldn't do well as a programmer or any other coding job you might try to get.
Here it is:
var Spencer = {
age: 22,
country: "United States"
};

// make your own object here called me
var me = {
age: 11,
country: "United States"
};
Okay, so copying the framework for Spencer, you get "me".

If you want to understand how it works, keep reading.

First you have to tell the computer that this is a bunch of information with the keyword var.
Then, you have to give it a name. Simple enough, but the typical way is camelCase. You put two words and mash them into one, and the second, not the first, is capitalized. Or you could do like this: variable_name, etc. Really, though, it doesn't matter.
Then you have to fill in the information the computer is going to store for you. Here, Codecademy wants your age and the country you live in. So the info looks like this for the age:
age: 30,
The comma is only there if this is not the last bit of information. Mimicking the age, we now turn to the second info bit, the country we live in.
country: United States
Keep in mind that after the object name we use curly braces to store the info, and that there always has to be an equals sign (=) in the variable, right after the name and before the curly braces. So all in all the object looks like this:
var me = {
age: 30,
country: United States
}
We don't use the comma after the last info bit. I don't know why, it's the way the computer works.
Hope you understand these now!
:smile:


#6

Because the comma-, is used as a separator
and the last property has nothing to be separated from


#7

thanks for the answer. and i understand he was trying to help but im being forced to take this class and its dumb cause i think this is pointless. but i appreciate the answer.


#8

@jorfizzle23,
It is all about object's
which is the heart of OO or Object-Oriented programming !.