-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassDefinition.js
77 lines (63 loc) · 2.31 KB
/
classDefinition.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
71
72
73
74
75
76
77
class CoronaVirus {
constructor(people, virus, ppeNumber) {
this.people = people;
this.virus = virus;
this.ppeNumber = ppeNumber;
}
// getters
get theVirus() {
return "I'm a freakin virus! I'm infecting " + this.multiplies() + " people today."
}
get deliverableSafetyItems() {
return this.item;
}
get ppeNow() {
let ppes = ['masks', 'all PPE (personal protective equipment)', 'gowns', 'gloves'];
let i = Math.floor(Math.random() * ppes.length);
let typesOfPpe = () => {
return this.item !== undefined ? this.item : ppes[i]
}
let injectAmericanIndividualism = (country) => {
return country + ". HAHA! Syyyyyke!! It's all about " + country + " " + country + "!";
}
let curveBall = (country) => {
return country === 'USA' ? injectAmericanIndividualism(country) : (country + ". ");
}
return "The amount of " + typesOfPpe() + " you'll get today is " + this.ppeNumber + " units. " + "And it's coming from " + curveBall(this.randomCountry())
}
get teamwork() {
return "Does worldwide teamwork make the dream work? " + (this.isThereTeamwork === 1 ? "Yes!" : "It depends on who you ask!")
}
get fullStory() {
return coronaDay42.theVirus + coronaDay42.ppeNow + coronaDay42.teamwork;
}
// setters
set teamwork(isThereTeamwork) {
this.isThereTeamwork = isThereTeamwork;
}
// Set in class instance declaration below if desired
// Otherwise will default to one of four values in getter ppeNow()
set safetyItems(item) {
if (item !== undefined) {
this.item = item;
} else {
this.item = 'PPE (personal protective equipment)';
}
}
// methods
multiplies() {
return this.virus * this.people;
}
randomCountry() {
let countryArray = ['China', 'South Korea', 'Germany', 'USA', 'Singapore', 'Spain', 'France', 'Italy', 'Canada'];
let i = Math.floor(Math.random() * countryArray.length);
return this.country = countryArray[i];
}
}
let randomPeopleNumber = Math.floor(Math.random() * 58494);
let randomPpeNumber = Math.floor(Math.random() * 58492084);
let randomYesOrNo = Math.floor(Math.random() * 2);
// creates a new instance of the class
const coronaDay42 = new CoronaVirus(randomPeopleNumber, 1000, randomPpeNumber);
coronaDay42.teamwork = randomYesOrNo;
console.log(coronaDay42.fullStory);