-
Notifications
You must be signed in to change notification settings - Fork 2
/
3_inheritance.html
119 lines (71 loc) · 2.96 KB
/
3_inheritance.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
class User {
constructor(nameValue, lastNameValue, emailValue) {
this.name = nameValue
this.lastName = lastNameValue
this.email = emailValue
this.active = true
}
updateEmail(newEmail) {
this.email = newEmail
}
}
const user1 = new User('German', 'Alvarez', '[email protected]')
console.log('El correo de', user1.name, 'es', user1.email)
user1.updateEmail('[email protected]')
console.log('El correo de', user1.name, 'ahora es', user1.email)
class Player extends User {
constructor(firstName, lastName, email, nickValue) {
super(firstName, lastName, email)
this.nick = nickValue
this.tokens = 100
}
spendTokens(charge) {
if (this.tokens >= charge) {
this.tokens -= charge
} else {
throw new Error(`No puedes gastar ${charge} tokens ya que solo te quedan ${this.tokens}`)
}
}
}
const player1 = new Player('Yasmina', 'Moreno', '[email protected]', 'rUbiSelA_99')
console.log('La jugadora', player1.nick, 'en realidad se llama', player1.name, 'y su correo es', player1.email)
player1.updateEmail('[email protected]')
console.log('Y ahora su correo es', player1.email)
console.log('LA jugadora tiene', player1.tokens, 'tokens')
player1.spendTokens(30)
console.log('LA jugadora tiene', player1.tokens, 'tokens')
// player1.spendTokens(90)
class Witch extends Player {
constructor(nameValue, lastNameValue, emailValue, nickValue, spellValue) {
super(nameValue, lastNameValue, emailValue, nickValue)
this.spell = spellValue
}
makeSpell() {
console.warn('La bruja', this.nick, '(que en realidad se llama', this.name, '), te atacó con su hechizo', this.spell)
}
}
const witch1 = new Witch('Charo', 'García', '[email protected]', 'RuBiSeLah_95', 'Abra cadabra')
witch1.makeSpell()
class Gnome extends Player {
constructor(nameValue, lastNameValue, emailValue, nickValue, attackValue) {
super(nameValue, lastNameValue, emailValue, nickValue)
this.attack = attackValue
}
attackNow() {
console.warn('el gnomo', this.nick, 'te atacó con', this.attack, '... ¡QUÉ GUARRO!')
}
}
const gnome1 = new Gnome('Raul', 'Whatever', 'djghs@msn,es', 'mÒ_óreNiKoh_23', 'ESCUPITAJOS')
gnome1.attackNow()
</script>
</body>
</html>