-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimals.js
More file actions
52 lines (49 loc) · 1019 Bytes
/
animals.js
File metadata and controls
52 lines (49 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Owner(animals) {
this.animals = animals;
this.care = function() {
console.log('## cuddle ##');
this.animals.forEach(function(a) {
a.cuddle()
});
console.log('## feed ##');
this.animals.forEach(function(a) {
a.feed()
});
console.log('## cuddle ##');
this.animals.forEach(function(a) {
a.cuddle()
});
}
}
function Badger() {
this.happy = 0;
this.cuddle = function() {
if (this.happy > 0) {
console.log('Wheeewwww')
} else {
console.log('Grrrr')
}
};
this.feed = function() {
++this.happy;
console.log('miam miam miam');
}
}
function GoldFish() {
this.seed = Math.random();
this.blob = function() {
if (this.seed > 0.5) {
console.log('*blub*')
} else {
console.log('*blob*')
}
};
this.cuddle = function() {
this.blob();
};
this.feed = function() {
this.blob();
}
}
var cha = new Owner([new GoldFish(), new Badger(), new GoldFish(), new GoldFish()]);
cha.care();