RSS

Objects and Methods made my head swim – but not any more!

05 Jul

I’ve really been struggling with understanding objects and methods from my work on codecademy. Although it is a great site, because it is crowdsourced teaching, some topics just don’t get the best treatment. It’s not all that common to haveImage someone who knows how to do something well and have them also be able to explain it well to a student (just ask some of my poor victim / students from my first several semesters teaching).

Nevertheless, I trolled through some of the Q&A sessions looking for a good explanation of the material I was struggling with and couldn’t find anything that answered my question very well. What I did find, though, were some decent pieces of ideas that I thought I could combine into a more comprehensive bolus of work that reviewed the topics I just covered, provided some practice working with objects and methods and even a switch statement.

Here’s the setup:

Shermer High school. A couple famous students go there and we can make up Objects representing each of these students using a constructor. Also, each of these students has a brand name jacket that they cherish and these are also created as objects. So the twist is: we’re creating objects(Persons) who have other objects(jackets) as one of their properties. Furthermore, to make this exercise include methods as well, I’ve added ‘wash’ and ‘sew’ methods. Each time one of these methods is carried out, the jackets are changed (e.g. when you wash a jacket, you lose a button. When you sew a jacket, you add a button).

What I wanted to accomplish was to make these objects and methods and learn how to call them so that they carry out their work. Presented below is this program with some annotation and console.log statements that should clear up what’s going on.

Please let me know if this is helpful to anyone – or if this could be cleaned up and done in a more clear and concise way.

// Constructor to make jackets
function Jacket(brand){
switch(brand){
case jordache:
this.make = “Jordache”;
this.buttons = 5;
this.color = “blue”;
break;

case gap:
this.make = “Gap”;
this.buttons = 2;
this.color = “brown”;
break;

case oldNavy:
this.make = “Old Navy”;
this.buttons = 3;
this.color = “white”;
break;
}

}

//constructor to make people
function Person(name,age,brand) {
this.name = name; //unique
this.age = age; //unique
this.brand = new Jacket(brand); //object
this.school = “Shermer High”;    //constant
this.sayHello = function(){
console.log(“Say Hello to ” +this.name+”, student at “+this.school);
};
//method that washes jacket – loses a button each time
this.wash = function(){
console.log(“You just washed “+this.name +”‘s Jacket.”);
this.brand.buttons = this.brand.buttons-1;
console.log(“That jacket now has “+this.brand.buttons+” buttons.”);
return this.brand.buttons;
};
this.sew = function(){
console.log(“You just mended “+this.name+”‘s jacket.”);
this.brand.buttons = this.brand.buttons +1;
console.log(“That jacket now has “+this.brand.buttons+” buttons.”);
};

}

// Make three people using a constructor
var geek = new Person(“Anthony Michael Hall”, 14, oldNavy);
var girl = new Person(“Molly Ringwald”, 15, gap);
var caroline = new Person(“Caroline”, 17, jordache);

//now complete with uses of these objects and methods
console.log(“Getting started”);
girl.sayHello();

//console.log(girl.brand.make);
console.log(girl.name+ ” has an awesome “+girl.brand.make +” jacket.”);
girl.wash();
girl.wash();
geek.sayHello();
geek.wash();
girl.sew();
girl.sew();

console.log(“finished”);

 

Tags: , , , , , , , , ,

4 responses to “Objects and Methods made my head swim – but not any more!

  1. Diego Dominguez (@DfDomin)

    August 26, 2012 at 9:39 pm

    I’m looking your code. Is very advanced, but i’m understanding because is explained. Your biography is incredible

     
  2. Grace

    March 8, 2013 at 10:23 am

    Speaking of codeacademy and other code-teaching devices, I wanted to get in touch with you. You once commented on my blog at AAAS, and lo and behold you gained an avid reader to your site. Alas, now I need your help. I have an interview with Ave Lauringson on Monday! I’m supposed to talk to her about the new ProgeTiiger programme in Estonia, then write about it for AAAS. Except, I don’t know what questions to ask!

    Thus, I come to you since you have some experience in coding, and I wanted to see if my questions were intelligent enough and if there is anything else you’d like to add to the list.

    Cheers,
    Grace

     
    • downhousesoftware

      March 9, 2013 at 12:36 pm

      Dear Grace:

      Thank you very much for the email. I think that your meeting with Ave Lauringson will be great. She’s doing some incredible work in Estonia that will maintain their leadership in education. As with all programs of this sort, I think the most daunting barrier would be bringing the teachers up to speed in a way that they can truly provide leadership and stay ahead of their students.

      I have a child in second grade myself who I am interested in teaching programming, but I know that there is little support or resources available for this sort of education in his school. I wonder how Ms. Lauringson would approach initiating a project of this sort in the US – a regional approach? or extramurally? or as part of a smaller group, such as Montessori schools? I live in a region that is currently trying to push technology very aggressively (Kansas City), including the addition of Google Fiber, a virtual sandbox for entrepreneurs, and other initiatives relating to tech. Perhaps KC would be a good region to emulate her program.

      Another item you might wish to pursue is how she feels that her coding initiative will affect the rest of the curriculum with respect to what logic / math / etc. classes will be required for students (perhaps much sooner than they would otherwise begin studying these topics)?

      I don’t know if any of this is useful to you. None of my questions or comments specifically comes from my coding experience, but I am happy you asked for my input and I hope it at least gets you thinking.

      Sincerely,

      Jack Treml

       
      • Grace

        March 9, 2013 at 2:40 pm

        Thank you, Jack! These points definitely get me thinking. I only had some basics such as “tell me about your programme” down because I couldn’t find much about it other than the standard teaching kids how to programme, and the first step is to get a bunch of computers in schools.

        I will definitely ask her some of your questions as well. They are a lot more intuitive for someone that programmes and knows the field. You see, AAAS often has me interviewing people that are far outside of my expertise, but overlap in interest of education and public engagement. I really had no idea where to start on this one.

        Again, than you. I’ll send you a link to the interview as soon as I realise it’s published. Hopefully you’ll find some use of it. =) If you think of anything else between now and early Monday morning, just drop a line. I’ll add it to the list. Ms. Lauringson is pretty approachable, and I’m sure she wouldn’t mind answering a bunch of questions.

        Cheers,
        Grace

         

Leave a Reply to downhousesoftware Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: