Programming in Javascript - Object Orientation


Complete the Khan Lessons. This assignment assumes you have completed the lesson that takes you through the Khan Academy tutorials assigned to you. Your teacher will track that you did all of tutorials by looking for the green circles for each tutorial that you will see linked vertically on the right of the Khan tutorial pages. There are points for this assignment for doing the tutorials assigned to you.

  1. Do the Khan project Bookshelf. Note that there are points in all programs for your use of style:
    Save this program at Khan with the name lastname_bookshelf.

  2. Create a Google Doc for this assignment called lastname_ooAnswers. Consider this Khan code, which is similar to that used in the videos:
    
    /* 1  */ var Winston = function(nickname, age, x, y) {
    /* 2  */     this.nickname = nickname;
    /* 3  */     this.age = age;
    /* 4  */     this.x = x;
    /* 5  */     this.y = y;
    /* 6  */ };
    /* 7  */ var winstonTeen = new Winston("Winsteen", 15, 20, 50);
    /* 8  */ var winstonAdult = new Winston("Mr. Winst-a-lot", 30, 229, 50);
    /* 9 */ var drawWinston = function(winston) {
    /* 10 */     fill(255, 0, 0);
    /* 11 */     var img = getImage("creatures/Winston");
    /* 12 */     image(img, winston.x, winston.y);
    /* 13 */     var txt = winston.nickname + ", " + winston.age;
    /* 14 */     text(txt, winston.x+20, winston.y-10);
    /* 15 */ };
    /* 16 */ var winstons = [winstonTeen, winstonAdult];
    /* 17 */ drawWinston(winstons[0]);
    /* 18 */ drawWinston(winstons[1]);
    
    In your lastname_ooAnswers document explain this code line by line (each line should have an entry explaining what the line does). Use correct terminology including object, constructor, dot notation, property, array . Explaining the this syntax is a bit tricky. Explaining how the objects are created, stored, and passed into the draw function is also tricky. Pay close attention to those aspects.