-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animal.js
70 lines (54 loc) · 1.52 KB
/
Animal.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict"
console.log(`Animal class running ok`);
const sex = Object.freeze({
female: "female",
male: "male",
})
class Animal {
#id
#name
#age
#sex
#personality
#familyType
#fosterCare
constructor (id, name, age, sex, personality, familyType, fosterCare) {
this.#id = parseInt(id);
this.#name = name;
this.#age = parseInt(age);
this.#sex = sex;
this.#personality = personality;
this.#familyType = familyType;
this.#fosterCare = fosterCare;
}
getId() { return this.#id }
getName() { return this.#name }
getAge() { return this.#age }
getSex() { return this.#sex }
getPersonality() { return this.#personality }
getFamilyType() { return this.#familyType }
getFosterCare() { return this.#fosterCare }
setId(newId) {
let pass = prompt(`Magic password required: `);
if (pass = 727284) {
return this.#id = newId;
} else {
return alert(`Incorrect password, who are you? ('e.e)`);
}
}
setName(newName) { return this.#name = newName }
setFosterCare() { return this.#fosterCare = true }
toString() {
return `
<pre>
Id: ${this.getId()}
Name: ${this.getName()}
Age: ${this.getAge()}
Sex: ${this.getSex()}
Personality type: ${this.getPersonality()}
Purrfect family type: ${this.getFamilyType()}
Currently in foster care: ${this.getFosterCare()}
</pre>
`
}
}