Skip to content

Commit 21fe3ff

Browse files
committed
#8 - javascript
1 parent 3e5d539 commit 21fe3ff

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
class Auto{
2+
constructor(marca, color){
3+
this.marca = marca;
4+
this.color = color;
5+
}
6+
7+
imprimirDatos(){
8+
console.log(`El auto es marca ${this.marca} y es de color ${this.color}.`);
9+
}
10+
}
11+
12+
let auto1 = new Auto('peugeout', 'rojo');
13+
auto1.imprimirDatos()
14+
15+
auto1.marca = 'fiat';
16+
auto1.color = 'azul';
17+
auto1.imprimirDatos()
18+
19+
20+
21+
22+
/////////////////////////////////////////
23+
// Extra
24+
25+
class Pila{
26+
constructor(){
27+
this.arr = [];
28+
}
29+
30+
add(elem){
31+
this.arr.push(elem);
32+
}
33+
delete(){
34+
this.arr.pop();
35+
}
36+
cantElem(){
37+
console.log('\n',this.arr.length);
38+
}
39+
mostrar(){
40+
console.log('\n',this.arr);
41+
}
42+
}
43+
44+
class Cola{
45+
constructor(){
46+
this.arr = [];
47+
}
48+
add(elem){
49+
this.arr.push(elem);
50+
}
51+
delete(){
52+
this.arr.shift();
53+
}
54+
cantElem(){
55+
console.log('\n',this.arr.length);
56+
}
57+
mostrar(){
58+
console.log('\n',this.arr);
59+
}
60+
61+
}
62+
63+
console.log('//////// Pila')
64+
let pilas = new Pila();
65+
pilas.add(2);
66+
pilas.add(3);
67+
pilas.add(4);
68+
pilas.mostrar();
69+
pilas.cantElem();
70+
pilas.delete();
71+
pilas.mostrar();
72+
pilas.cantElem();
73+
74+
console.log('//////// Cola')
75+
let colas = new Cola();
76+
colas.add(2);
77+
colas.add(3);
78+
colas.add(4);
79+
colas.mostrar();
80+
colas.cantElem();
81+
colas.delete();
82+
colas.mostrar();
83+
colas.cantElem();
84+

0 commit comments

Comments
 (0)