View difference between Paste ID: pqCK3GmN and ZAiBu1bc
SHOW: | | - or go back to the newest paste.
1
var forestCows = [
2
  {name: "Legolas", type: "calf", hadCalf: null},
3
  {name: "Gimli", type: "bull", hadCalf: null},
4
  {name: "Arwen", type: "cow", hadCalf: null},
5
  {name: "Galadriel", type: "cow", hadCalf: null},
6
  {name: "Eowyn", type: "cow", hadCalf: "Legolas"}
7
];
8
9
Object.prototype.noCalvesYet = function () {
10
  if (this.type == 'cow' && this.hadCalf == null) {
11
    return true;
12
  }
13
};
14
Array.prototype.countForBreeding = function () {
15
  var numToBreed = 0;
16
  for ( var i = 0; i < this.length; i++) {
17
    if (this[i].noCalvesYet() == true) {
18
      numToBreed++;
19
    }
20
  }
21
  return numToBreed;
22
};
23-
console.log('jak duzo nieocielonych krow', forestCows.countforBreeding());
23+
console.log('powinny byc 2 nieocielone krowy', forestCows.countForBreeding());