forked from Make-School-Labs/few-2.1-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-09.ts
35 lines (27 loc) · 984 Bytes
/
example-09.ts
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
// 🧠 Improve the type safety of this file using your work from example-08
// 🛠️ TODO:
// 1. Import Kaiju and KaijuType from example-8.ts
// 2. Add proper parameter types for `kaiju` and `city`
// 3. Fix the switch statement to use the KaijuType enum instead of strings
// import { Kaiju, KaijuType } from './example-08' // uncomment if running standalone
function rampage(kaiju, city) {
const { name, type, power } = kaiju;
let action: string;
switch (type) {
case 'ape':
action = 'smash';
break;
case 'lizard':
action = 'burn';
break;
case 'flying':
action = 'flap';
break;
}
return `${name} ${action} over ${city} causing ${power * 10000} damage!`;
}
// 👾 Define Kaiju instances using the Kaiju class and KaijuType enum
const gojira = new Kaiju('Gojira', 90, KaijuType.lizard);
// Add two more Kaiju monsters here...
console.log(rampage(gojira, 'Tokyo'));
// Call rampage with the other Kaiju and cities!