Monday, May 25, 2015

Same Old Story

var Porridge = function(temperature) {
    this.quality = temperature;
    this.name = "porridge";
    this.use = "eating";
};

var Chair = function(size) {
    this.quality = size;
    this.name = "chair";
    this.use = "sitting in";
};

var Bed = function(hardness) {
    this.quality = hardness;
    this.name = "bed";
    this.use = "sleeping in";
};

var Bear = function(home, temp, size, hardness) {
    this.home = home;
    this.utterance = "";
    this.possessions = [
        new Porridge(temp),
        new Chair(size),
        new Bed(hardness)
    ];
};
Bear.prototype.goOut = function () {
    this.home = false;
};
Bear.prototype.comeBack = function () {
    this.home = true;
};
Bear.prototype.speak = function (line) {
    this.utterance = line;
    console.log(this.utterance);
};

var Poppa = new Bear(true,"too hot","too big","too hard");
var Momma = new Bear(true,"too cold","too small","too soft");
var Baby = new Bear(true,"just right","just right","just right");

var Bears = [Poppa, Momma, Baby];
for (var b = 0; b < Bears.length; b++) {
    Bears[b].goOut();
}

var Person = function(iq) {
    this.iq = iq;
    this.utterance = "";
};
Person.prototype.test = function(obj) {
    this.utterance = obj.quality;
    console.log(this.utterance);
};
var Goldilocks = new Person(0);

for (p = 0; p < Bear.prototype.possessions.length; p++) {
    for (b = 0; b < Bears.length; b++) {
    Goldilocks.test(Bears[b].possessions[p]);
    }
}

for (b = 0; b < Bears.length; b++) {
    Bears[b].comeBack();
}

for (p = 0; p < Bear.prototype.possessions.length; p++) {
    for (b = 0; b < Bears.length; b++) {
    Bears[b].speak("Someone's been " + Bears[b].possessions[p].use +
     " my " + Bears[b].possessions[p].name + ".");
    }
}

throw new Error();