-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDogFactory.js
More file actions
52 lines (46 loc) · 1.15 KB
/
DogFactory.js
File metadata and controls
52 lines (46 loc) · 1.15 KB
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 dogFactory(name, breed, weight) {
return {
_name: name,
get name() {
return this._name;
},
set name(newName){
if(typeof newName==='string')
{return this._name=newName
}else{
console.log('please type a string.')}
},
_breed: breed,
get breed() {
return this._breed;
},
set breed(newBreed){
if(typeof newBreed==='string'){
return this._breed=newBreed
} else{
console.log('please type a string.')
}},
_weight: weight,
get weight() {
return this._weight;
},
set weight(newWeight){
if(typeof newWeight === 'number'){
return this._weight=newWeight}
else {console.log('please type a number')}
},
bark() {
return "ruff! ruff!";
},
eatTooManyTreats() {
return this._weight++;
}
}
}
const dog1 = dogFactory('Joe', 'Pug', 27);
console.log(dog1.name)
console.log(dog1.weight)
console.log(dog1.breed)
dog1.eatTooManyTreats();
console.log(dog1.weight)
console.log(dog1.bark())