Javascript - Help w/ prototypes and properties? -


i'm writing code javascript class , i've hit dead end. task make "virtual pet app" has several properties: hungry, ill, , lonely. there 2 prototypes (a dog , fish) share main pet object. here code far:

'use strict';  // pet prototype var pet = {     name: 'your pet',     hungry: true,     ill: false };   pet.feed = function(){     this.hungry = false;     return this.name + ' full.'; };   pet.newday = function(){     (var prop in this){         if (typeof this[prop] === 'boolean'){             this[prop] = true;         }     }     return 'good morning!'; };   pet.check = function(){     var checkval = '';      (var prop in this){         if (typeof this[prop] === 'boolean'             && this[prop] === true){             checkval += this.name + ' ' + prop + '. ';         }      }     if (typeof this[prop] === 'boolean'             && this[prop] === false){             checkval = this.name + ' fine.';     }     return checkval; };  // fish prototype var fish = object.create(pet);   fish.clean = function(){     this.ill = false;     return this.name + ' likes clean tank.'; };   // dog prototype var dog = object.create(pet);   // lonely property dog.lonely = false;   dog.walk = function(){     this.ill = false;     return this.name + ' enjoyed walk!'; }   dog.play = function(){     this.lonely = false;     return this.name + ' loves you.'; } 

there more code, think guys gist now. problem check function not work properly...

console.log(mydog.check());      // fido hungry. console.log(mydog.feed());       // fido full. console.log(mydog.check());      // fido fine. console.log(myfish.check());     // wanda hungry. console.log(myfish.feed());      // wanda full. console.log(myfish.check());     // wanda fine. console.log(mydog.newday());     // morning! console.log(myfish.newday());    // morning! console.log(mydog.check());      // fido hungry. fido lonely. fido ill. 

this output supposed be, output:

fido hungry.  fido full. (an empty string) wanda hungry.  wanda full. (an empty string) morning! morning! fido hungry. fido lonely. fido ill.  

can direct me towards why check function not printing pet.name fine, , instead printing empty string? in advance!

it looks intent display is fine if none of properties true. instead of checking this[prop], makes no sense because value of prop after loop unpredictable, check whether checkval has been set loop.

pet.check = function(){     var checkval = '';      (var prop in this){         if (typeof this[prop] === 'boolean'             && this[prop] === true){             checkval += this.name + ' ' + prop + '. ';         }      }     if (checkval == ''){         checkval = this.name + ' fine.';     }     return checkval; };