-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeiroDesafio.js
More file actions
52 lines (40 loc) · 1.15 KB
/
primeiroDesafio.js
File metadata and controls
52 lines (40 loc) · 1.15 KB
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
class ListaCompra{
constructor(){
this.itens=[],
this.quantidades=[]
}
adicionarItem(nome, quantidade) {
this.itens.push(nome);
this.quantidades.push(quantidade);
}
mostrarItens(){
for (let i =0; i< this.itens.length;i++){
console.log(`Item: ${this.itens[i]}, Quantidade: ${this.quantidades[i]}`)
}
}
removerItem(nome) {
const index = this.itens.indexOf(nome);
if (index > -1) {
this.itens.splice(index, 1);
this.quantidades.splice(index, 1);
}
else{
console.log("item não encontrado!")
}
}
atualizarQuantidade(nome, novaQuantidade) {
const index = this.itens.indexOf(nome);
if (index > -1) {
this.quantidades[index] = novaQuantidade;
}
else{
console.log('Item não encontrado')
}
}
}
let listaCompras = new ListaCompra();
listaCompras.adicionarItem("maça", 50);
listaCompras.adicionarItem("banana", 10);
listaCompras.mostrarItens();
listaCompras.atualizarQuantidade("uva", 20)
listaCompras.mostrarItens();