-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (35 loc) · 976 Bytes
/
Copy pathscript.js
File metadata and controls
40 lines (35 loc) · 976 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
class Hero {
constructor(nome, idade, tipo) {
this.nome = nome;
this.idade = idade;
this.tipo = tipo;
}
atacar() {
let ataque;
switch (this.tipo.toLowerCase()) {
case 'mago':
ataque = 'magia';
break;
case 'guerreiro':
ataque = 'espada';
break;
case 'monge':
ataque = 'artes marciais';
break;
case 'ninja':
ataque = 'shuriken';
break;
default:
ataque = 'ataque desconhecido';
}
console.log(`o ${this.tipo} atacou usando ${ataque}`);
}
}
const guerreiro = new Hero('Guerreiro', 20, 'guerreiro');
guerreiro.atacar();
const ninja = new Hero('Ninja', 25, 'ninja');
ninja.atacar();
const mago = new Hero('Mago', 30, 'mago');
mago.atacar();
const monge = new Hero('Monge', 35, 'monge');
monge.atacar();